Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How do you bring a value with a RemoteEvent?

Asked by
iRexBot 147
7 years ago

So I'm trying to bring a value using a RemoteEvent with FE on So I was thinking "()" might be the value carry but it won't work as it prints "iRexBot"

Here is the script:

Localscript:

01local Players = game:GetService('Players')
02local Player = Players.LocalPlayer
03local Storage=game:GetService('ReplicatedStorage')
04local Event=Storage:WaitForChild('ParticalEvent')
05 
06 
07function onClick()
08    local num = 1
09    Event:FireServer(num)
10end
11 
12script.Parent.MouseButton1Click:Connect(onClick)

Script:

1local Storage = game:GetService('ReplicatedStorage')
2local Event = Storage:WaitForChild('ParticalEvent')
3 
4--Core
5 
6function onFired(num)
7    print(num)
8end
9Event.OnServerEvent:Connect(onFired)

1 answer

Log in to vote
1
Answered by
XAXA 1569 Moderation Voter
7 years ago
Edited 7 years ago

OnServerEvent implicitly passes the player that fired it in the first place as the first argument (which is why it printed your name, iRexBot).

You can fix it by adding an extra parameter to your onFired function.

1function onFired(player, num)
2    print(num)
3end
Ad

Answer this question