Eventive
|
  |
| Joined: 28 Jul 2011 |
| Total Posts: 9827 |
|
|
| 10 Apr 2017 02:36 PM |
User Input Service is getting messy for me.
I have this script where if a player is touching a part, then they press E a gui pops up. I have it all in a localscript, because I only want it to replicate to the client that triggered it.
However if one player is touching it, another one dosn't have to touch the part and when they type or something if they press E it triggers the gui for those two players.
How would I do it so it doesn't get messy like this and only goes for the client?
ATR'er since 2013. |
|
|
| Report Abuse |
|
|
devHoodie
|
  |
| Joined: 04 Nov 2008 |
| Total Posts: 30332 |
|
|
| 10 Apr 2017 02:37 PM |
lol
r+://487783315r+://467523707r+://215869124 |
|
|
| Report Abuse |
|
|
|
| 10 Apr 2017 02:40 PM |
| If it's in a local script, then just use the local player. |
|
|
| Report Abuse |
|
|
Eventive
|
  |
| Joined: 28 Jul 2011 |
| Total Posts: 9827 |
|
|
| 10 Apr 2017 02:41 PM |
I do but it gets messy still. https://www.roblox.com/games/726922007/quest
ATR'er since 2013. |
|
|
| Report Abuse |
|
|
|
| 10 Apr 2017 02:44 PM |
Dude
The script that uses UIS is run on the client firing the input. |
|
|
| Report Abuse |
|
|
Eventive
|
  |
| Joined: 28 Jul 2011 |
| Total Posts: 9827 |
|
|
| 10 Apr 2017 02:50 PM |
@Intended What's your point? I need it to run on the client but it messes up, and interferes with other clients.
ATR'er since 2013. |
|
|
| Report Abuse |
|
|
devHoodie
|
  |
| Joined: 04 Nov 2008 |
| Total Posts: 30332 |
|
|
| 10 Apr 2017 02:53 PM |
| how about you don't replicate anything and do everything client sided? You know? canChat = false part.Touched:connect(function() pressEtoTalk.Visible = true canChat = true end ######## ## ### if Input.KeyCode == Enum.KeyCode.E then -- do chat stuff end idk r+://487783315r+://467523707r+://215869124 |
|
|
| Report Abuse |
|
|
|
| 10 Apr 2017 02:53 PM |
Is this a joke?
You're doing something very wrong. You should post your code here. |
|
|
| Report Abuse |
|
|
devHoodie
|
  |
| Joined: 04 Nov 2008 |
| Total Posts: 30332 |
|
|
| 10 Apr 2017 02:54 PM |
roblox ur bad
and yes post your code
r+://487783315r+://467523707r+://215869124 |
|
|
| Report Abuse |
|
|
Eventive
|
  |
| Joined: 28 Jul 2011 |
| Total Posts: 9827 |
|
|
| 10 Apr 2017 02:55 PM |
Everything is in a LocalScript, and the script is long, and probably messy but here
local player = game.Players.LocalPlayer local gui = player.PlayerGui.ChatGuiDominus local uis = game:GetService('UserInputService') local guy = game.Workspace.Dominus:WaitForChild("") local trig = guy.Trigger local anim = guy.Humanoid:LoadAnimation(trig.Wave) local label = gui.Frame.TextLabel local RE = game.ReplicatedStorage:WaitForChild("RemoteEvent") local msg1 = "Hello, "..player.Name local msg2 = "I am Eventive" local msg3 = "Nice to meet you." local msg4 = "Hope you enjoy this replica of the character-interaction-chat." local msg5 = "Have fun and share with your friends!" local canProgress = true local canInteract = false
trig.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then if hit.Parent.Name ~= "" then local char = hit.Parent canInteract = true guy.HumanoidRootPart.GUI.Enabled = true ---- Computer ---- uis.InputBegan:Connect(function(input, gameProcessed) if input.KeyCode == Enum.KeyCode.E then if not canInteract then return end if not gui.Enabled then RE:FireServer('speed') for i,v in pairs(guy:GetChildren()) do if v:IsA("MeshPart") then v.Anchored = false end end anim:Play() wait(1.5) anim:Stop() wait(0.5) for i,v in pairs(guy:GetChildren()) do if v:IsA("MeshPart") then v.Anchored = true end end end gui.Enabled = true end end) ---- Mobile ---- uis.TouchTap:connect(function(input, gameProcessed) if not canInteract then return end if not gui.Enabled then char.Humanoid.WalkSpeed = 0 for i,v in pairs(guy:GetChildren()) do if v:IsA("MeshPart") then v.Anchored = false end end anim:Play() wait(1.5) anim:Stop() for i,v in pairs(guy:GetChildren()) do if v:IsA("MeshPart") then v.Anchored = true end end end gui.Enabled = true end) end end end)
trig.TouchEnded:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then if hit.Parent.Name ~= "" then guy.HumanoidRootPart.GUI.Enabled = false canInteract = false end end end)
progress = 0 repeat wait() until gui.Enabled if gui.Enabled then for i = 1,############o #label.Text = label.Text..msg1:sub(i,i) wait(0.04) end progress = 1 ---- Computer ---- uis.InputBegan:connect(function(input, gameProcessed) if input.KeyCode == Enum.KeyCode.E then if progress == 1 then repeat wait() until label.Text == msg1 label.Text = "" for i = 1,############o # label.Text = label.Text..msg2:sub(i,i) wait(0.04) end progress = 2 elseif progress == 2 then repeat wait() until label.Text == msg2 label.Text = "" for i = 1,############o # label.Text = label.Text..msg3:sub(i,i) wait(0.04) end progress = 3 elseif progress == 3 then repeat wait() until label.Text == msg3 label.Text = "" for i = 1,############o # label.Text = label.Text..msg4:sub(i,i) wait(0.04) end progress = 4 elseif progress == 4 then repeat wait() until label.Text == msg4 label.Text = "" for i = 1,############o # label.Text = label.Text..msg5:sub(i,i) wait(0.04) end progress = 5 elseif progress == 5 then player.Character.Humanoid.WalkSpeed = 16 gui.Enabled = false label.Text = "" canInteract = false wait(2) canInteract = true return end end end) ---- Mobile ---- uis.TouchTap:connect(function(input, gameProcessed) if progress == 1 then repeat wait() until label.Text == msg1 label.Text = "" for i = 1,############o label.Text = label.Text..msg2:sub(i,i) wait(0.04) end progress = 2 elseif progress == 2 then repeat wait() until label.Text == msg2 label.Text = "" for i = 1,############o # label.Text = label.Text..msg3:sub(i,i) wait(0.04) end progress = 3 elseif progress == 3 then repeat wait() until label.Text == msg3 label.Text = "" for i = 1,############o # label.Text = label.Text..msg4:sub(i,i) wait(0.04) end progress = 4 elseif progress == 4 then repeat wait() until label.Text == msg4 label.Text = "" for i = 1,############o # label.Text = label.Text..msg5:sub(i,i) wait(0.04) end progress = 5 elseif progress == 5 then player.Character.Humanoid.WalkSpeed = 16 gui.Enabled = false label.Text = "" canInteract = false wait(2) canInteract = true return end end) end
ATR'er since 2013. |
|
|
| Report Abuse |
|
|
|
| 10 Apr 2017 02:57 PM |
Oh my life.
If you're just trying to make a GUI show up this is way overcomplicated. |
|
|
| Report Abuse |
|
|
Eventive
|
  |
| Joined: 28 Jul 2011 |
| Total Posts: 9827 |
|
|
| 10 Apr 2017 02:58 PM |
I want the gui to show up then everytime they press e it changes the text, but it gives a type effect when the text shows up.
ATR'er since 2013. |
|
|
| Report Abuse |
|
|
Eventive
|
  |
| Joined: 28 Jul 2011 |
| Total Posts: 9827 |
|
|
| 10 Apr 2017 02:58 PM |
press E if they're on Pc or tap if they're on mobile
ATR'er since 2013. |
|
|
| Report Abuse |
|
|
Eventive
|
  |
| Joined: 28 Jul 2011 |
| Total Posts: 9827 |
|
|
| 10 Apr 2017 03:00 PM |
only if they're touching the part tho
ATR'er since 2013. |
|
|
| Report Abuse |
|
|
devHoodie
|
  |
| Joined: 04 Nov 2008 |
| Total Posts: 30332 |
|
|
| 10 Apr 2017 03:01 PM |
this is not meant to offend this is purely constructive criticism
your code is really inefficient.
You should learn to use tables(more specifically modules) to iterate through npc chatting
your code is badly put together...
r+://487783315r+://467523707r+://215869124 |
|
|
| Report Abuse |
|
|
devHoodie
|
  |
| Joined: 04 Nov 2008 |
| Total Posts: 30332 |
|
|
| 10 Apr 2017 03:01 PM |
Learn to use ContextActionService instead of UIS for cross platform support
r+://487783315r+://467523707r+://215869124 |
|
|
| Report Abuse |
|
|
Eventive
|
  |
| Joined: 28 Jul 2011 |
| Total Posts: 9827 |
|
|
| 10 Apr 2017 03:02 PM |
That's how I used to coding Hard to break the habit of it.
ATR'er since 2013. |
|
|
| Report Abuse |
|
|
devHoodie
|
  |
| Joined: 04 Nov 2008 |
| Total Posts: 30332 |
|
|
| 10 Apr 2017 03:03 PM |
I understand. I was the same then started scripting with performance and efficiency in mind.
r+://487783315r+://467523707r+://215869124 |
|
|
| Report Abuse |
|
|
Eventive
|
  |
| Joined: 28 Jul 2011 |
| Total Posts: 9827 |
|
|
| 10 Apr 2017 03:04 PM |
I also dont fully know what's efficient and whats not.
I know shorter is more efficent, but I don't know how to reduce most of the lines.
ATR'er since 2013. |
|
|
| Report Abuse |
|
|
Eventive
|
  |
| Joined: 28 Jul 2011 |
| Total Posts: 9827 |
|
| |
|
WK100
|
  |
| Joined: 13 Oct 2008 |
| Total Posts: 2835 |
|
|
| 10 Apr 2017 03:56 PM |
@Eventive
More efficient can simply be seen as fewer operations (and less operation time!) to finish a task. Looping forever isn't always the best idea, for example. |
|
|
| Report Abuse |
|
|
Eventive
|
  |
| Joined: 28 Jul 2011 |
| Total Posts: 9827 |
|
|
| 10 Apr 2017 04:01 PM |
hmm okay.
Can someone correct my code? Idk what to do.
ATR'er since 2013. |
|
|
| Report Abuse |
|
|
WK100
|
  |
| Joined: 13 Oct 2008 |
| Total Posts: 2835 |
|
|
| 10 Apr 2017 04:03 PM |
| To follow up, you could extract the duplicate parts into functions, and call the functions whenever required. Keep your code as flat as possible. You could try some pseudo-switch statements, by putting these functions into tables. Then call the table[key] where your key matches the progress. Examples to be found on ########################################## It's been a while since I've been into Lua programming so I can't help you out on the spot, nor do I have a lot of time to do so, but this could be a start to refactoring your code. |
|
|
| Report Abuse |
|
|
WK100
|
  |
| Joined: 13 Oct 2008 |
| Total Posts: 2835 |
|
|
| 10 Apr 2017 04:04 PM |
| Well, great. Sources are blocked. Anyway, you could easily Google 'lua-users wiki: Switch Statement' and find the link I tried to mention. |
|
|
| Report Abuse |
|
|
Eventive
|
  |
| Joined: 28 Jul 2011 |
| Total Posts: 9827 |
|
|
| 10 Apr 2017 04:34 PM |
Thanks but that didn't help too much.
Can someone please help? I have been trying all day to get this fixed.
ATR'er since 2013. |
|
|
| Report Abuse |
|
|