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 2 years ago

LOCAL SCRIPT

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

SERVER SCRIPT

game.Players.PlayerAdded:Connect(function(player)
    game.ReplicatedStorage.Delivered.OnServerEvent:Connect(function(player, cashMultiplyer)
            print(cashMultiplyer.Name)
            print(cashMultiplyer)
    end)
end)

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 — 2y

1 answer

Log in to vote
3
Answered by 2 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

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

ServerScript

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

Answer this question