Command script doesn't work

Greetings Developer, Can someone help me fixing my command script?

local Group = 000000
local MinRank = 0

game.Players.PlayerAdded:Connect(function(player)
	script.TrainerTitle:Clone().Parent = player.Character.Head
	
	player.Chatted:Connect(function(message)
		if string.lower(message) == "!train" and player:GetRankInGroup(Group) >= MinRank then
			player.Character.Head.TrainerTitle.Enabled = true
		end
	end)
end)

[NOTE] It says that the bug is on the line 5.

image

1 Like

Try this instead:

local a = script.TrainerTitle:Clone()
a.Parent = player.Character.Head

I tried that before but It didn’t work.
It says Head isn’t valid!
image

Check if it exists before doing anything with it.

local Character = PlayerInstance.Character
if Character then
	local Head = Character:FindFirstChild('Head')
	if Head then
		-- code.
	end
end

It still doesn’t work:

local Group = 6419782
local MinRank = 12

game.Players.PlayerAdded:Connect(function(player)
	local Character = player.Character
	local Clone = script.TrainerTitle:Clone()
	
	if Character then
		local Head = Character:FindFirstChild('Head')
		if Head then
			Clone.Parent = Head
		end
	end
	
	player.Chatted:Connect(function(message)
		if string.lower(message) == "!train" and player:GetRankInGroup(Group) >= MinRank then
			player.Character:FindFirstChild("Head").TrainerTitle.Enabled = true
		end
	end)
end)

Line 17.

Use a CharacterAdded event.

New Script:

local Group = 6419782
local MinRank = 12

game.Players.PlayerAdded:Connect(function(player)

	
	player.CharacterAdded:Connect(function(char)
		
		local Clone = script.TrainerTitle:Clone()
		
		local Head = char:WaitForChild('Head')
		
		player.Chatted:Connect(function(message)
			if string.lower(message) == "!train" and player:GetRankInGroup(Group) >= MinRank then
				Head.TrainerTitle.Enabled = true
			end
		end)
	end)
end)

Still doesn’t work…

Add prints and tell us what prints…

Are there any errors?

Yes, it says Line 15…

What is the error???..

It’s just saying Line 15…

Can you send a photo?..

Sure…

I just made a new Script and it works.

local Group = 6419782
local MinRank = 12

game.Players.PlayerAdded:Connect(function(player)
	
	local isTrainer = false
	
	player.Chatted:Connect(function(message)
		
		if string.lower(message) == "!train" and player:GetRankInGroup(Group) >= MinRank then
			
			isTrainer = true
			
			local Clone = game.ReplicatedStorage.TrainerTitle:Clone()
			Clone.Parent = player.Character.Head
			
		end
	end)
end)

Anyways, thanks for helping.

Here’s a fixed version of your script.

local Group = 6419782
local MinRank = 12
local TrainerTitle = script.TrainerTitle

game.Players.PlayerAdded:Connect(function(player)
	local Character = player.Character or player.CharacterAdded:Wait()
	local Head = Character:FindFirstChild('Head')
	if Head then
		TrainerTitle:Clone().Parent = Head
	end
	
	player.Chatted:Connect(function(message)
		if string.lower(message) == "!train" and player:GetRankInGroup(Group) >= MinRank then
			Head.TrainerTitle.Enabled = true
		end
	end)
end)

You’re welcome.

And, you were doing a few things wrong, you might be able to spot what.

Can you still send the photo?

I’m interested in what it says.

Sure…

Is there any reason you quoted that?

No, sorry! It’s just a mistake.

Errors don’t just show:

So can you send a photo? Never seen that before…