Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

1 comment

0

tysm

This discussion is preserved as it was. New answers, comments, and votes are closed.