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

Why does my Remote Event think the parameter is the player???

Asked by 3 years ago

LOCAL SCRIPT

1function onTouch()
2    local player = game.Players.LocalPlayer
3    local cashMultiplyer = script.CashMultiplyer.Value
4    game.ReplicatedStorage.Delivered:FireServer(player, cashMultiplyer)
5end
6game.Workspace.Brick.Touched:connect(onTouch)

SERVER SCRIPT

1game.Players.PlayerAdded:Connect(function(player)
2    game.ReplicatedStorage.Delivered.OnServerEvent:Connect(function(player, cashMultiplyer)
3            print(cashMultiplyer.Name)
4            print(cashMultiplyer)
5    end)
6end)

The server script prints my username instead of script.CashMultiplyer.Name

0
You don't need to define the player, you're sending it to the server. the solution is just to remove the 'player' in the FireServer parameters MarkedTomato 810 — 3y

1 answer

Log in to vote
3
Answered by 3 years ago

LocalScripts will pass LocalPlayer to whatever function is on the receiving end when calling the :FireServer() function. Which means you do not need to create a variable and add it as an argument as it's basically done for you. Fixed scripts:

LocalScript

1function onTouch()
2    local cashMultiplyer = script.CashMultiplyer.Value
3    game.ReplicatedStorage.Delivered:FireServer(cashMultiplyer)
4end
5game.Workspace.Brick.Touched:connect(onTouch)

ServerScript

1game.ReplicatedStorage.Delivered.OnServerEvent:Connect(function(player, cashMultiplyer)
2    print(cashMultiplyer.Name)
3    print(cashMultiplyer)
4end)
Ad

Answer this question