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;
01 | local 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 |
10 | script.Parent.MouseButton 1 Click:Connect(leftClick) |
I used the dev forum to help me a bit https://developer.roblox.com/en-us/api-reference/function/Instance/FindFirstChild
What if you make a debounce using an if statement? Like this:
01 | local DB = false |
02 | local 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 |
12 | end |
13 |
14 | --Function for resetting your debounce |
15 | local function ResetDB() |
16 | DB = false |
17 | end |
18 |
19 | script.Parent.MouseButton 1 Click:Connect(leftClick) |
EDIT: also, define a local for your clone.
1 | local cln = game.Workspace.Classes.CatMaid:Clone() |
2 | cln.Parent = game.StarterPlayer |
3 | cln.Name = "StarterCharacter" |