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

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

Asked by 4 years ago

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)


0
hit means the LocalPlayer, you do realise? RobloxBuildingCareer 0 — 4y

1 answer

Log in to vote
0
Answered by
Prestory 1395 Moderation Voter
4 years ago
Edited 4 years ago

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)
Ad

Answer this question