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

I have a problem with data in FireServer, how to fix it?

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?

1 comment

0

Try where it says // game.ReplicatedStorage.BuyItem:FireServer(player, name) \ to remove player, in the client its auto sent. So the code under is fine. But the top one, Remove player, name.

1 answer

: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().

2 comments

0

Oh, I had no idea about this. Now everything's working, thanks!

0

Not to ask for reputation, but please accept my answer.

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