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

Why doesn't this script run upon clicking a brick?

Edited the title so it seemed less like a request.

Hello again, I'm attempting to apply clothing to a player when they click a brick, this is the script I have:

function onClicked(player)
	if player:FindFirstChild("Shirt") then
		player:FindFirstChild("Shirt"):Destroy()
	end
	if player:FindFirstChild("Pants") then
		player:FindFirstChild("Pants"):Destroy()
	end
	      Instance.new("Shirt",player)
	      player.Clothing.Name = "Shirt"
	      Instance.new("Pants",player)
	      player.Clothing.Name = "Pants"
	      player:FindFirstChild("Shirt").ShirtTemplate = "http://www.roblox.com/asset/?id=28574189"
          player:FindFirstChild("Pants").PantsTemplate = "http://www.roblox.com/asset/?id=28572684"
     if player:FindFirstChild("Shirt Graphic") then
	           player:FindFirstChild("Shirt Graphic"):Destroy()
    end
end


script.Parent.ClickDetector.MouseClick:Connect(onClicked)


However, upon clicking the brick, nothing happens. No errors in the console, the script doesn't even run. And yes, I do have an active click detector within the part I'm testing with, the mouse even changes to the click. I feel like I'm missing something, but I can't quite tell what.

1 answer

✓ Accepted answer

It is seemed like you are checking shirt, pant in the player, not character. This is how you get character by Player

Player.Character

So now you will add .Character Before : WaitForChild at line 5 & 2. Hope that helped you

1 comment

0

This fixed it, thank you so much!

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