Hi, I have a problem. In this local script:
local player = game.Players.LocalPlayer wait(5) local name = "Brumb" print(name) script.Parent.MouseButton1Click:Connect(function() game.ReplicatedStorage.BuyItem:FireServer(player, name) end)
It prints "Brumb". But in script in ServerScriptService:
game.ReplicatedStorage.BuyItem.OnServerEvent:Connect(function(player, name) wait(0.1) print(name) local cost = player.PlayerGui.MainMenu.Shop.Characters.CharactersFrame:FindFirstChild(name).Cost.Value if player.Coins.Value == cost or player.Coins.Value > cost then print("Can buy "..name) else print("Can't buy "..name) end end)
It prints my username as name. Why is it happening?
:FireServer()
by default sets the first argument to the player, so you don't need to do this yourself. That's why the name
parameter is set to the player, because :FireServer()
sets the first argument to the player, then the rest of the arguments. The solution is to remove the player
in the :FireServer()
.