Hello!
I currently joined the devforum and I would like some help for my code to get improved.
I currently made a TextButton that makes a player unlock a certain hat when reaching a certain level on my game.
It works well when equipping and unequipping the hat. But whenever the character resets or respawns I cant equip the hat anymore.
Details
When the player character dies. It doesn’t save the hat that is equipped. What I mean is saved is when the character equipped the hat and then suddenly dies. It doesn’t come back.
As the issue above, when the character dies it doesnt let the player equip it anymore. But the text changes to equip and unequip.
Here is a example of my code.
script.Parent.MouseButton1Click:Connect(function()
if Player.leaderstats.Level.Value >= 10 and equippedhalo == false then
equippedhalo = true
givehat = hat:Clone()
givehat.Parent = character
wait()
script.Parent.Text = "Equipped"
elseif Player.leaderstats.Level.Value >= 10 and equippedhalo == true then
equippedhalo = false
character:FindFirstChild("TestHalo"):Destroy()
script.Parent.Text = "Equip"
elseif Player.leaderstats.Level.Value <= 10 then
script.Parent.Text = "Locked"
end
end)
If you do help me out of this. I would like to thank you very much
If you want to explain furthermore detail’s about the coding.
You can dm me on discord. Classyblade#9882
script.Parent.MouseButton1Click:Connect(function()
if Player.leaderstats.Level.Value >= 10 then -- Check the level alone first
if equippedhalo then -- Then check if it's equipped
givehat = hat:Clone()
givehat.Parent = character
wait()
script.Parent.Text = "Equipped"
else
character:FindFirstChild("TestHalo"):Destroy()
script.Parent.Text = "Equip"
end
equippedhalo = not equippedhalo -- Then invert the boolean variable (If it's [true] it will become [not true] aka [false] and vice versa)
else -- if level is not greater than or equal to 10 then do this:
script.Parent.Text = "Locked"
end
end)
as for the problem of why it doesn’t work after the character dies, I will need more info on that because with the info you gave I have no clue. Is it a script or a local script? What is script.Parent?
When I implemented your code it had a error. Tried to fix it but I didnt really fix anything since I’m new to this.
I should send the full code so that you can understand the script.
local Player = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent
local hat = game.ServerStorage.Halos:WaitForChild("TestHalo")
local character = Player.Character
local equippedhalo = script.Parent.Equipped.Value
equippedhalo = false
script.Parent.MouseButton1Click:Connect(function()
if Player.leaderstats.Level.Value >= 10 and equippedhalo == false then
equippedhalo = true
givehat = hat:Clone()
givehat.Parent = character
wait()
script.Parent.Text = "Equipped"
elseif Player.leaderstats.Level.Value >= 10 and equippedhalo == true then
equippedhalo = false
character:FindFirstChild("TestHalo"):Destroy()
script.Parent.Text = "Equip"
elseif Player.leaderstats.Level.Value <= 10 then
script.Parent.Text = "Locked"
end
end)
This is my full code.
My answer’s for your questions.
script.Parent refers to the TextButton that the script is in.