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
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"