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

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

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

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.

4 comments

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.

0

There are problems: if you don't have 0 or 6 victories, then nothing appears above your head

0

I have corrected the code above Boi, I made a mistake, sorry about that!

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!

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