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

Read Description I Dont Know How To Explain?

Asked by 3 years ago

SOOOOOOOOOO the script wont put sips.value equal to coins.value when the player touches a part

local plr = game.Players -- code that wont work
local part = script.Parent

plr.PlayerAdded:Connect(function(player)
    part.Touched:Connect(function()
        local sips = player.leaderstats.Sips
        local Coins = player.leaderstats.Coins

        Coins.Value = sips.Value -- Coins.Value = Sips.Value
        print(Coins.Value)
    end)
end)

And The Gui's Text Wont change when the max number is set to another for example

The GUI Shows 15/15 but when i change the max value the gui dosent changes the max number

local max = script.Parent.Max
local Money = script.Parent.Sips.CoinCounter
local plr = game.Players.LocalPlayer
local Gold = plr.leaderstats.Sips
while true do
    Money.Text = Gold.Value.."/"..max.Value
    wait(0.1)
end

1 answer

Log in to vote
0
Answered by 3 years ago

I would guess that the player instance caught on line 4 isn't an always updated reference, anyway instead of adding the touched event on the player added try to do something like this instead:

(considering the script was inside of the part)

script.Parent.Touched:Connect(function(part)

local player = game.players:GetPlayerFromCharacter(part.Parent)
if player then
    local ls = player:WaitForChild("leaderstats")
    if ls then
        ls.Coins.Value = ls.Sips.Value
    end
end

end)
Ad

Answer this question