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

How do I pass arg through FireClient()?

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

✓ Accepted answer

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

1 comment

0

Thank you!

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