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

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

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

1 comment

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

1 answer

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)

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