DevTurtIe
(DevTurtle)
February 3, 2021, 2:41pm
#1
Hello,
My issue that i have with my script is that the size of the level bar is becoming to big for everyone who is helping me i am NOT using the normal size i am using scale and not offset this are some pictures of my problem
When it is acting normal it does this
When it goes wrong it does this
I have 2 scripts look in the explorer i have them selected
LevelSystem script
game.Players.PlayerAdded:Connect(function(player)
local level = Instance.new("IntValue", player)
level.Name = "Level"
level.Value = 1
local exp = Instance.new("IntValue", level)
exp.Name = "Current"
exp.Value = 0
local maxExp = Instance.new("IntValue", level)
maxExp.Name = "Max"
maxExp.Value = 100
exp.Changed:Connect(function(val)
if exp.Value >= maxExp.Value then
-- Do stuff.
level.Value = level.Value + 1
exp.Value = 0
maxExp.Value = maxExp.Value + 10
end
end)
end)
workspace:WaitForChild("GiveEXP").ClickDetector.MouseClick:Connect(function(player)
player.Level.Current.Value = player.Level.Current.Value + 25 -- Use this whenever you want to give the player exp.
end)
Main Script
-- Player-related variables.
local player = game.Players.LocalPlayer
local level = player:WaitForChild("Level")
local current = level:WaitForChild("Current")
local max = level:WaitForChild("Max")
-- UI-related variables.
local gui = script.Parent
local label1 = gui.Parent.Level
local label = label1:WaitForChild("Level")
local exp1 = gui.Parent.Xp
local exp = exp1:WaitForChild("Xp")
local bar = gui.Parent.Xpbar
-- Change stats upon join.
label.Text = "Level "..level.Value
exp.Text = current.Value.."/"..max.Value.." XP"
bar.Size = UDim2.new(current.Value/max.Value, 0, 0.034, 0)
level.Changed:Connect(function(val)
label.Text = "Level "..level.Value
exp.Text = current.Value.."/"..max.Value.." XP"
bar.Size = UDim2.new(current.Value/max.Value, 0, 0.034, 0)
end)
current.Changed:Connect(function(val)
exp.Text = current.Value.."/"..max.Value.." XP"
bar.Size = UDim2.new(current.Value/max.Value, 0, 0.034, 0)
end)
also if you help me and need the size when the bar is full it is {0.426, 0},{0.034, 0}
also i have some good news i will upload this item for free if it can be fixed cause i always do that with my items!
Auxintic
(Aux)
February 3, 2021, 2:52pm
#2
Would you mind exporting a download so I could fiddle with it and see what’s wrong?
1 Like
DevTurtIe
(DevTurtle)
February 3, 2021, 2:54pm
#3
Sure here is the file also the part in the worspace don’t delete it if you click the part it will give you xp
LevelSystem.rbxl (30.8 KB)
1 Like
Auxintic
(Aux)
February 3, 2021, 2:55pm
#4
Alright, thank you. I’ll take a look at it now.
1 Like
Auxintic
(Aux)
February 3, 2021, 2:58pm
#5
Ah I see what’s going on, you haven’t parented the XpBar correctly.
Try to parent it to XpBackground
. Hope you can figure it out, if not let me know.
Edit: fixed typo
2 Likes
DevTurtIe
(DevTurtle)
February 3, 2021, 2:59pm
#6
I will try it if it doesn’t work i will let you know
so i need to parent the xp bar with the background
Auxintic
(Aux)
February 3, 2021, 2:59pm
#7
Yeah, and you’ll need to update your code so the reference to the xpbar is correct.
Arcilios
(Arcilios)
February 3, 2021, 2:59pm
#8
The bar was not Parented to “XpBackground”
I did some changes and fixed your script accordingly here you go.
Fixed.rbxl (31.1 KB)
Auxintic
(Aux)
February 3, 2021, 2:59pm
#9
Don’t spoonfeed, that’s not how developers learn
DevTurtIe
(DevTurtle)
February 3, 2021, 3:00pm
#10
oh ok ty that’s easyer than doing it at my self so ty for your help
Arcilios
(Arcilios)
February 3, 2021, 3:00pm
#11
Told him the reason and I changed 1 number in the script o-o
2 Likes
Let me take a look I feel its and problem with the UI when the bar moves accross
Arcilios
(Arcilios)
February 3, 2021, 3:02pm
#13
I suggest you look into :TweenSize() it’ll benefit you in the longer run and with the xp bar you’re making currently.
DevTurtIe
(DevTurtle)
February 3, 2021, 3:02pm
#14
lol it’s already fixed but ty everyone to help me
Your bar.Size = UDim2.new(current.Value/max.Value, 0, 0.034, 0) is wrong change it it controls the bar
DevTurtIe
(DevTurtle)
February 3, 2021, 3:02pm
#16
ye i was gonna do that but i don’t really know how to i’m not really great with tweening i did it one time but it was hard for me cause i don’t use it alot!
Auxintic
(Aux)
February 3, 2021, 3:03pm
#17
Nope, that’s not the issue.
He parented his XpBar to the ScreenGui so a relative size of 0.5 took up half of the screen instead of half of the XpBarBackground.
DevTurtIe
(DevTurtle)
February 3, 2021, 3:06pm
#18
but can you maybe tell me how to use tweenservice in that script also i don’t really need the file to let it get fixed i wanna try it at myself cause then i will get better at scripting
Auxintic
(Aux)
February 3, 2021, 3:08pm
#20
Instead of directly setting the Size you can use TweenSize() or a similar option: https://developer.roblox.com/en-us/api-reference/property/Tween/TweenInfo
But I’ll leave that up to you as a challenge.