Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

This script won't give the player a new title. Help?

Asked by 5 years ago

I made a script that give you a title depending on how many wins you have, but when you have 6 wins, the title doesn't change, and no errors appear in the output.

game.Players.PlayerAdded:Connect(function(p)
    p.CharacterAdded:Connect(function(char)
    local wins = p.leaderstats.Victories
    local titles = game.ServerStorage.Titles
    if wins.Value == 0  and wins.Value < 5 then
        titles.Noob:Clone().Parent = char.Head
        char.Head:WaitForChild("Noob").Enabled = true
    if wins.Value == 6 and wins.Value < 14 then
        print(wins.Value)
        char.Head:WaitForChild("Noob"):Destroy()
        titles.Amateur:Clone().Parent = char.Head
        char.Head:WaitForChild("Amateur").Enabled = true
        end
    end
    end)
end)

1 answer

Log in to vote
0
Answered by
Romul 21
5 years ago
Edited 5 years ago

First off, you are forgetting to acknowledge if they have 5 wins. So on that section of the code you should refer to less than or equal to 5.

I believe the code is not pulling through because you are waiting on the Noob title to be given though it wouldn't if they have 6 or more wins. Additionally, I would clean up the code a bit to continue on with your if statements as elseif and remove that extra useless end. Here is a fixed version I believe should work:

game.Players.PlayerAdded:Connect(function(p)
    p.CharacterAdded:Connect(function(char)
        local wins = p.leaderstats.Victories
        local titles = game.ServerStorage.Titles
        if wins.Value <= 5 then
            titles.Noob:Clone().Parent = char.Head
            char.Head:WaitForChild("Noob").Enabled = true
        elseif wins.Value >= 6 and wins.Value <= 14 then
            if char.Head:FindFirstChild("Noob") then
                char.Head.Noob:Remove()
            end
            titles.Amateur:Clone().Parent = char.Head
            char.Head:WaitForChild("Amateur").Enabled = true
        end
    end)
end)

I'm not the best at explaining things, if this does work but you are still confused on how to fix it, please comment back or look for other scripters to comment that are more experienced than myself. Hope this helps!!

******EDIT I adjusted it so that the giver works properly for 5 or less wins and 6 or more. On the first line, you just need to reference if they have 5 or less wins, there is no need to see if they have 0 wins, this does it already. On the elseif line, you have to make sure you compare greater than or equal to on the first part of the phrase, not just equal to.

0
I added an if statement to check if the player had the Noob title that needs to be removed. The way you have it coded though, it shouldn't give it anyways, so that if statement checking for the Noob title isn't really needed. Romul 21 — 5y
0
There are problems: if you don't have 0 or 6 victories, then nothing appears above your head Boi52893642864912 69 — 5y
0
I have corrected the code above Boi, I made a mistake, sorry about that! Romul 21 — 5y
0
Please check the reply and let me know if it solved the issue. Don't forget to accept the answer if it works! Thanks! Romul 21 — 5y
Ad

Answer this question