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

How do I make a value directed towards a remote event not me?

Asked by 3 years ago
Edited by Leamir 3 years ago

Please encode Lua code in the Lua block code tag (look for the Lua icon in the editor).

I'm having trouble making a simulator and I made a local script in the tool to fire to the remote. For some reason the script thinks the amount is me even though it's not even directed towards me. Here is the script(also I didn't use local player because that bugged also)

script.Parent.Activated:Connect(function()
    local playername = script.Parent.Parent.Name
    local player = game.Players:FindFirstChild(playername)
    local amount = game.ReplicatedStorage.Apple:FindFirstChild("1").Amount
    game.Workspace.RemoteHandler.Eat:FireServer(player,amount)
end)

1 answer

Log in to vote
1
Answered by
Evil2DS 25
3 years ago
Edited 3 years ago

When a remote event is fired by the client, the OnServerEvent function will automatically have the parameter of said client that fired it.

Example

event.OnServerEvent:Connect(function(player)
    print(player.Name)
end)

You don't need to pass the player through, and the only thing you need to pass through is your "amount" variable.

Local Script

script.Parent.Activated:Connect(function()
    local amount = game.ReplicatedStorage.Apple:FindFirstChild("1").Amount
    game.Workspace.RemoteHandler.Eat:FireServer(amount)
end)

Server Script

event.OnServerEvent:Connect(function(player, amount)
    -- put code here
end)
0
tysm CandyWreckEpicness 115 — 3y
Ad

Answer this question