Script in startercharacter deletes

When i put a script under a click detector in a startercharacter it deletes?


error ^
in game V
image
In studioV
image

Any objects inside StarterCharacter is going to be cloned each time a new Character Model is spawned inside the workspace, and the old Parts from the old Character will become destroyed/nil

It would help if you could provide that script with its lines of codes, maybe you’re destroying it somewhere

local clickDetector = script.Parent
local function onClick(player)
	print(player.Character:GetFullName())
	local attachm = game.Workspace:WaitForChild("slenderW0lf_YT"):WaitForChild("Right Arm").HoldAttachment
	attachm.Parent = player.Character:WaitForChild("Right Arm")
	
	local ID = "http://www.roblox.com/asset/?id=8201632631"
	local animation = Instance.new("Animation")
	animation.AnimationId = ID
	
			player.Character.Humanoid:LoadAnimation(animation):Play()
	
end
clickDetector.MouseClick:Connect(onClick)

this is just the script but theres no delete in any other script

Why are you exactly putting a Part inside the StarterCharacter again? I believe that’s only for StarterCharacter'Scripts'

You could just instead put the Part inside the workspace instead, and reference the ClickDetector inside from there

local clickDetector = workspace.Part:WaitForChild("ClickDetector")
local ID = "http://www.roblox.com/asset/?id=8201632631"
local animation = Instance.new("Animation")
animation.AnimationId = ID
	
local function onClick(player)
    local Char = player.Character

    if Char and Char:FindFirstChild("Right Arm") and Char:FindFirstChild("Humanoid") then
	    print(Char:GetFullName())

        local Animator = Char.Humanoid:WaitForChild("Animator")
        local AttachM = Char["Right Arm"].HoldAttachment
        AttachM.Parent = Char["Right Arm"]

        Animator:LoadAnimation(animation):Play()
    end
end

clickDetector.MouseClick:Connect(onClick)

Also couple minor things I saw, but I slightly edited it a bit

yes but im trying to put the script into a part thats welded onto the character
image

Since you’re cloning the Part onto the Character, move the Script as it’s own singular object inside StarterCharacterScripts & rename the Part to something else so that you can easily find it via the script, and change line 1 to this:

local clickDetector = script.Parent:WaitForChild("PartNameHere"):WaitForChild("ClickDetector")

Honestly unsure why it’s deleting unless if you installed some sort of malicious plugin on your Studio

1 Like

Got it. Its strange why its deleting. Thanks

It’s because you have a server script inside the StarterPlayer folder (which is for local scripts exclusively). Server scripts inside that folder won’t replicate to the client and as such won’t be cloned into the player’s character model each time it is reloaded/respawned.

You should be cloning a script from ReplicatedStorage/ServerStorage into the ClickDetector when it is parented to the player’s character model, as opposed to directly placing a server script inside the StarterCharacter model which is parented to the StarterPlayer folder.

--define the player here etc

local detector = character:WaitForChild("Part"):WaitForChild("ClickDetector")
local clickScript = game.ReplicatedStorage:WaitForChild("ClickScript")
clickScript.Clone().Parent = detector --clone server script into clickdetector instance