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

My script to change Gui Front on EXP changed won't work?

width = script.Parent.Size.X
P = script.Parent.Parent.Parent.Parent
Front = script.Parent
P.leaderstats.EXP.Changed:connect(function()
    if P.leaderstats.EXP > (P.leaderstats.MaxEXP) then
        P.leaderstats.Level.Value = P.leaderstats.LastLevel.Value + 1
        P.leaderstats.EXP.Value = 0
        P.leaderstats.MaxEXP.Value = P.leaderstats.Level.Value * 59
    end

local width = P.leaderstats.EXP / P.leaderstats.Level / 59
Front.Size = UDim2.new(0, width, 0, Front.Size.Y.Offset)

end)

3 comments

0

Just Turn TextScaled on.

1

Shouldn't there be a 'Value' after .EXP and .Level?

0

^ Lines 11 and 12

1 answer

Credit to Wizzy011 for pointing this out

Your problem is that you failed to index the Value of the EXP and Level Values on line 11 and line 12 - so you're essentially attempting to use arithmetic on an Instance, which will return in an error.

local width = script.Parent.Size.X
local P = script.Parent.Parent.Parent.Parent
local Front = script.Parent

P.leaderstats.EXP.Changed:connect(function()
	if P.leaderstats.EXP > (P.leaderstats.MaxEXP) then
		P.leaderstats.Level.Value = P.leaderstats.LastLevel.Value + 1
		P.leaderstats.EXP.Value = 0
		P.leaderstats.MaxEXP.Value = P.leaderstats.Level.Value * 59
	end
	local width = P.leaderstats.EXP.Value / P.leaderstats.Level.Value / 59
	Front.Size = UDim2.new(0, width, 0, Front.Size.Y.Offset)
end)

Additionally, you can just turn the TextScaled property to true.

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