Money display for tycoon not working in multiplayer

I am trying to make a tycoon in which you can collect money by stepping on a brick .In single player everything works as intended, but when I try to use the “Team test” feature the GUI stops displaying how much money you have to collect. I do not know what is causing this, in both multiplayer and single player collecting money works fine, but the sign always says 0 even if you have more than 0.

Script that destroys parts:

wait(0.5)
destroyPart = script.Parent
givemoney = game.ServerStorage.moneytogive
players = game.Players:GetPlayers()
print(players)
destroyPart.Touched:Connect(function(hit)
    print("h")
    if hit.BrickColor == BrickColor.new("Magenta") then
accessory and other parts in the map.
        local moneyToGive = hit:FindFirstChild("MoneyToGive")
           givemoney.Name = "moneytogive"
        givemoney.Value = givemoney.Value + moneyToGive.Value
        hit:Destroy()
    end
end)

script for part that gives money:

local ServerStorage = game:GetService("ServerStorage")
debounce = false

script.Parent.Touched:Connect(function(hit)
    wait()
    local moneyToGive = ServerStorage:FindFirstChild("moneytogive")
    local Character = hit.Parent
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    local Humanoid = Character:FindFirstChildOfClass("Humanoid")
    if debounce == false and Humanoid ~= nil and player.Team == game.Teams["Purple Tycoon"] then
        debounce = true
        player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + moneyToGive.Value
        moneyToGive.Value = 0
        wait(4)
        debounce = false
    end
end)

script for gui that displays how much money you have:

wait(1)
text = script.Parent
local ServerStorage = game:GetService("ServerStorage")
local money = ServerStorage:FindFirstChild("moneytogive")
money:GetPropertyChangedSignal("Value"):Connect(function()
    text.Text = money.Value
end) 

(btw this one is a localscript)

1 Like

I am just confused… at ur local script u are trying to get the object from ServerStorage, this is probably the problem here since u cant do that.
Instead create a remote event that will fire certain client

2 Likes

We changed it to a normal script, and it still doesn’t work.

Well yes, u cant handle GUI by the server script

What do you mean? Can you help offer a solution to our problem?

Like a said, on server script u make an event that will listen for change of the intValue and when that happens it sends the value of it as an argumant through remote event to local script. There u pick it and set ur Gui.Text to that argument

1 Like

To start, you’re changing the properties of an object in ServerStorage, which may or may not affect the script. Either parent the value to the player or localize it. Assuming that first excerpt was written in a Script and not a LocalScript.

The are mutiple issues we have with this code, however it can be fixed!

To start off with, like others said you are trying to view ServerStorage locally, to combat this it leaves us with 2 main solutions:

  1. Change the LocalScript into a Server Script, then editing the script futher
  2. Use a Remote Function.

I recommend reading these:

Do you still have the issues I’ll link you the thread that may help you