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

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

Asked by 3 years ago

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?

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. GIidingDuck 5 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

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

0
Oh, I had no idea about this. Now everything's working, thanks! fellix_yt 5 — 3y
0
Not to ask for reputation, but please accept my answer. deeskaalstickman649 475 — 3y
Ad

Answer this question