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

How do I pass arg through FireClient()?

Asked by 3 years ago
script.Parent.Touched:Connect(function(hit)
    local char = hit.Parent
    local plr = game.Players:GetPlayerFromCharacter(char)
    coin = script.Parent
    if plr then
        game.ReplicatedStorage.CoinFire:FireClient(plr, coin)
    end
end)


--Sever script inside coin part
local var = true
game.ReplicatedStorage.CoinFire.OnClientEvent:Connect(function(plr, coin)
    if var == true then
        plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + 5
        var = false
    end
    coin:Destroy()
end)

--Local script inside playergui

Error: leaderstats is not a valid member of MeshPart "Workspace.Stage1.Meshes/coin"

There is a coin and when the player touches it I want the coin to give coins and disappear for the player

1 answer

Log in to vote
1
Answered by
appxritixn 2235 Moderation Voter Community Moderator
3 years ago

The server does not fire itself, unlike clients.

local var = true
local plr = game.Players.LocalPlayer
game.ReplicatedStorage.CoinFire.OnClientEvent:Connect(function(coin) -- plr arg not needed
    if var == true then
        plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + 5
        var = false
    end
    coin:Destroy()
end)

--Local script inside playergui
0
Thank you! Ind1v1duals 43 — 3y
Ad

Answer this question