cheshnut
(ruby)
October 7, 2023, 4:00pm
#1
script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage.Events.RemoteEvents.SpawnNPC:FireServer()
event.OnClientEvent:Connect(function(selected,chance)
print(selected)
print(chance)
end)
end)
storage.SpawnNPC.OnServerEvent:Connect(function()
selected = LuckHandler(luck.Name)
chance = luck.Name[selected]["Chance"]
print("A1")
print(selected)
print(chance)
game.ReplicatedStorage.Events.RemoteEvents.GiveNPC:FireClient(xPlayer,selected,chance)
end)
I clicked the GUI once which activates OnServerEvent, and then activates the ClientEvent, clicking once will produce one printed text from the Event.OnClientEvent but if you click more it will print more. Can someone please help me? Sorry if the problem isnt very clear.
dvynout
(dvynout)
October 7, 2023, 4:03pm
#2
script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage.Events.RemoteEvents.SpawnNPC:FireServer()
event.OnClientEvent:Connect(function(player, playerX, selected,chance)
print(selected)
print(chance)
end)
end)
As I know it takes “Player ” as the first member of the table in On…Events.
cheshnut
(ruby)
October 7, 2023, 4:04pm
#3
Hey uh i dont really understand what you mean by this, btw xPlayer is just LocalPlayer variable inside the server script.
cheshnut
(ruby)
October 7, 2023, 4:07pm
#4
also, i heard that player variable doesnt need to be called in the local script, it is called in the server scriot
game.ReplicatedStorage.Events.RemoteEvents.GiveNPC:FireClient(xPlayer,selected,chance)
Sniperkaos
(Swag Messiah)
October 7, 2023, 4:10pm
#5
runs every time you click the button
script.Parent.MouseButton1Click:Connect(function()
end)
fires once for each time connected
event.OnClientEvent:Connect(function(selected,chance)
print(selected)
print(chance)
end)
do you see the problem
1 Like
cheshnut
(ruby)
October 7, 2023, 4:13pm
#6
hi can you explain what you mean by “fires once for each time connected”?
Sniperkaos
(Swag Messiah)
October 7, 2023, 4:14pm
#7
each time you :Connect a RBXScriptSignal it will run the passed function once
1 Like
They meant that you are connecting the event too much times, do OnClientEvent:Once instead
1 Like
cheshnut
(ruby)
October 7, 2023, 4:17pm
#9
Thank you, I didn’t know :Once existed. I learned a lot, Thanks @Sniperkaos and you
Sniperkaos
(Swag Messiah)
October 7, 2023, 4:18pm
#10
you don’t even need to use once, just put the event outside the mousebutton1click connection so the event only connects once instead of connecting every time you click the button
3 Likes
dvynout
(dvynout)
October 7, 2023, 4:34pm
#11
Might be true, I’m not experienced with these stuffs too much.
system
(system)
Closed
October 21, 2023, 4:34pm
#12
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.