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

Why doesnt my morph replace the person who clicked its shirt?

I have a person and when a player clicks it? No errors do appear. Any suggestions are appreciated!

local debounce = true
local Click = script.Parent.ClickDetector

Click.MouseClick:Connect(function(hit)

	local h = hit.Parent:FindFirstChild("Humanoid")
	if (h ~= nil and debounce == true) then
		 
		debounce = false
		local p = script.Parent.Parent.Shirt:Clone()
		p.Parent = hit.Parent 
		wait(1)
		debounce = true
		print("it works")
	end
end)


1 comment

0

hit means the LocalPlayer, you do realise?

1 answer

You are not setting up your variables correctly for example this function returns the player not the character. Try the code i have provided for you below make sure its in a Script not a LocalScript.

Debounce = false

function Clicked (player)
	if not Debounce then
		Debounce = true
		local Shirt = script.Parent.Parent:WaitForChild('Shirt'):Clone()
		Shirt.Parent = workspace:WaitForChild(player.Name)
		wait(1)
		Debounce = false
		print('It Works')
	end
end

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

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