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

Read Description I Dont Know How To Explain?

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

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)

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