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

How do I detect if a thing has a certain child, and detect if it does?

Asked by 3 years ago

I'm trying to change the starter character to a cat maid, but if its already a cat maid I dont want it to keep cloning. Im fairly new the scripting;

local function leftClick()
    local found = workspace:FindFirstChild("StarterCharacter")
    if found then 
        print("kiwi")
        game.Workspace.Classes.CatMaid:Clone()
        game.Workspace.Classes.CatMaid:Clone().Parent = game.StarterPlayer
        game.Workspace.game.CatMaid:Clone().Name = "StarterCharacter"
    end
    end
script.Parent.MouseButton1Click:Connect(leftClick)

I used the dev forum to help me a bit https://developer.roblox.com/en-us/api-reference/function/Instance/FindFirstChild

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

What if you make a debounce using an if statement? Like this:

local DB = false
local function leftClick()
    if DB == true then return end
    DB = true
    local found = workspace:FindFirstChild("StarterCharacter")
    if found then 
        print("kiwi")
        game.Workspace.Classes.CatMaid:Clone()
        game.Workspace.Classes.CatMaid:Clone().Parent = game.StarterPlayer
        game.Workspace.game.CatMaid:Clone().Name = "StarterCharacter"
    end
end

--Function for resetting your debounce
local function ResetDB()
    DB = false
end

script.Parent.MouseButton1Click:Connect(leftClick)

EDIT: also, define a local for your clone.

local cln = game.Workspace.Classes.CatMaid:Clone()
cln.Parent = game.StarterPlayer
cln.Name = "StarterCharacter"
0
Thanks so much Radiant_Sparkles 69 — 3y
0
np rookiecookie153 53 — 3y
Ad

Answer this question