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 4 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;

01local function leftClick()
02    local found = workspace:FindFirstChild("StarterCharacter")
03    if found then
04        print("kiwi")
05        game.Workspace.Classes.CatMaid:Clone()
06        game.Workspace.Classes.CatMaid:Clone().Parent = game.StarterPlayer
07        game.Workspace.game.CatMaid:Clone().Name = "StarterCharacter"
08    end
09    end
10script.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 4 years ago
Edited 4 years ago

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

01local DB = false
02local function leftClick()
03    if DB == true then return end
04    DB = true
05    local found = workspace:FindFirstChild("StarterCharacter")
06    if found then
07        print("kiwi")
08        game.Workspace.Classes.CatMaid:Clone()
09        game.Workspace.Classes.CatMaid:Clone().Parent = game.StarterPlayer
10        game.Workspace.game.CatMaid:Clone().Name = "StarterCharacter"
11    end
12end
13 
14--Function for resetting your debounce
15local function ResetDB()
16    DB = false
17end
18 
19script.Parent.MouseButton1Click:Connect(leftClick)

EDIT: also, define a local for your clone.

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

Answer this question