Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

It's hard to explain. Trouble with RemoteEvents?

It's hard to explain but i will try.

Basically i have a RemoteEvent. I make a server script telling to fire all clients it x secs after the game starts:

remoteEvent:FireAllClients()

now i have a local script in a gui. When the player clicks a button, the script will determinate what is it going to do when the RemoteEvent fires to the client,in this case,print "i luv unicorns"

button.MouseButton1Up:connect(function()
	remoteEvent.OnClientEvent:connect(function()
		print'i luv unicorns'
	end)
end)

now THERE is the trouble. Let's suppose that the RemoteEvent has been called 1 sec after the game started. The player clicked the button 2 secs after the game started. Even if the player clicked AFTER the RemoteEvent has been fired, it still printed "i luv unicorns" and i don't know why...

help me.

4 comments

0

No one can test out a solution for you without proper scripts. The second script prints after it has been clicked once and then waits for a remote event to be fired.

0

Can you explain it better? I don't understand :/

0

Your script tries to look for something instead of waiting for it.

0

Well...i noticed another thing about this. If the server script fires like 3 times before the button has been clicked, it will appear 3 times "i luv unicorns" in the output

1 answer

✓ Accepted answer
local toggle = Instance.new("IntegerValue", button)
toggle.Name = "ToggleSetting"
toggle.Value = 2
button.MouseButton1Down:connect(function()
button["ToggleSetting"].Value = 1
end

remoteEvent:onClientEvent(connect(function)
if button["ToggleSetting"].Value = 1 then
print("i luv unicorns")
else
print("i dont luv unicorns im a noob")
end
end)

The reason I use a value is because I'm not sure if you changed a variable in a function it'd change everywhere. If I'm wrong do what you want. This way you can have 1 value and have it change when you click any button and have individual functions for said values.

3 comments

0

Oh. I think i got it. You mean to make a value to check if the event has been fired at this time ?

0

Sort of. You check what the setting is [loving or not loving unicorns] and then interpet the setting to do different functions. If you need any help, see my profile for my Discord.

0

I1m gonna use a value to check it... Thanks :)

This discussion is preserved as it was. New answers, comments, and votes are closed.