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

how do I send multiple values down in a remote event?

this script is for a gui that shows the players current cash. the players cash is a numbervalue named whatever the players username is, hence [player.name]. the local script is only getting one players cash value. so when Player1 has 100 cash and Player2 has 50 cash both of their GUI's say 100 cash. been at this for awhile and can't figure out a fix, any help is appreciated. (sorry for the title I literally have no idea how to word this question in one sentence)

--THE SERVER SCRIPT
local repStorage = game:GetService("ReplicatedStorage")
local remote = repStorage.remote

Players = game:GetService("Players")

while true do
	wait(1)
	for i, player in pairs(Players:GetPlayers()) do
	   cash = game.ServerStorage.PlayerMoney[player.Name]
	cash.Changed:connect(function() 
		remote:FireClient(player, cash.Value)
	end)
end

end
--THE LOCAL SCRIPT
local repStorage = game:GetService("ReplicatedStorage")
local remote = game.ReplicatedStorage:WaitForChild("remote")
wait(1)
local player = game.Players.LocalPlayer
local cashUpdate = player.PlayerGui.cashUpdate.Frame.TextLabel

remote.OnClientEvent:connect(function(cash)
	cashUpdate.Text = "CASH: " .. cash
end)

1 comment

0

As I don't know how to explain it properly, read this post, there is a good answer -- https://scriptinghelpers.org/questions/72744/do-i-have-to-use-multiple-remote-events-to-give-a-player-multiple-items

1 answer

Well, I did not really see any particular issue but considering it's a server script there may be some down-sides to using them.

Here's my rewritten version if it helps at all.

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local Remote = ReplicatedStorage:FindFirstChild("Remote")

coroutine.resume(coroutine.create(function()
    while true do
        wait(1)
        for _,Player in pairs(Players:GetPlayers()) do
            local PlayerMoney = ServerStorage:FindFirstChild("PlayerMoney") ~= nil and ServerStorage["PlayerMoney"]
            local Cash = PlayerMoney:FindFirstChild(Player.Name) ~= nil and PlayerMoney[Player.Name]
            Cash:GetPropertyChangedSignal("Name"):Connect(function()
                Cash.Name = Player.Name
            end)
            Cash:GetPropertyChangedSignal("Value"):Connect(function()
                Remote:FireClient(Player,Cash.Value)
            end)
            Players.PlayerRemoving:Connect(function(RemovingPlayer)
                if RemovingPlayer == Player then
                    Cash:Destroy()
                end
            end)
        end
    end
end))

3 comments

0

this is the error I got with this script. 16: attempt to index boolean with 'FireClient'

0

K, I edited it, try it now.

0

getting this now. 16: attempt to index nil with 'FireClient'. thanks for the help by the way

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