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

Covert a script from while true do to Changed:connect?

How would I change my script from a loop so that it only updates when the value of a player's XP changes?

Exp = script.Parent.Parent.Parent.Parent.Parent.LevelSystem.XP
Level = script.Parent.Parent.Parent.Parent.Parent.LevelSystem.Level

while true do
wait(0.5)
local pie = ( Exp.Value / (Level.Value * 200 + 1))
script.Parent.Size = UDim2.new( pie , 0 , 1 , 0)
end

2 comments

0

i think it does't work with values, but i dunno im new, kinda

0

1 local Exp = script.Parent.Parent.Parent.Parent.Parent.LevelSystem.XP 2 local Level = script.Parent.Parent.Parent.Parent.Parent.LevelSystem.Level 3 4 5 Exp.Changed:Connect(function() 6 local pie = ( Exp.Value / (Level.Value * 200 + 1)) 7 script.Parent.Size = UDim2.new( pie , 0 , 1 , 0) 8 end)

1 answer

✓ Accepted answer

Use the Changed event of the IntValue (note that this event is NOT the same as Changed of a nonvalue instance)

local levelSystem = script:FindFirstAncestor("LevelSystem")

local Exp, Level = levelSystem.XP, levelSystem.Level

Exp.Changed:Connect(function(val)
	local pie = val / (Level.Value * 200 + 1)
	script.Parent.Size = UDim2.new(pie,0,1,0)
end)

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