Scripts dont work when i manually set the player character, why?

  1. What do you want to achieve? Keep it simple and clear!
    I want to make it so scripts dont break when i set the Player.Character instead of using StarterCharacterScripts
  2. What is the issue? Include screenshots / videos if possible!
    When i make a rig morph and i want to test it using StarterPlayer, its scripts work fine and actually work but when i make a script so that when you do something, it morphs you into that specific rig but the scripts just.. stop working
  3. What solutions have you tried so far? Did you look for solutions on the Creator Hub?
    I’ve tried tutorials and searching on the forums, but no one seems to talk about or have a fix for it.

Do you guys have any idea on why this happens? i would be very thankful

Ill try to give you the footage, im getting it

Okay, heres a video

When i click, it will print something depending on what script detected it

(tell me if im using the wrong videos please)

Without StarterCharacterScripts

With StarterCharacterScripts

I don’t know what’s going on with your script, you never posted it.

What do you mean “you never posted it”? should i post the code of both scripts?

Post everything you think may help.. Use the </> option.

The code isnt probably that good because i was just messing around trying to find out why

StarterCharacterScripts code:

game.Players.LocalPlayer:GetMouse().Button1Down:Connect(function()
	print("clicked (the second detector, not parented to rig and uses StarterCharacterScripts)")
end)

Code without StarterCharacterScripts:

local player = game.Players.LocalPlayer

player:GetMouse().Button1Down:Connect(function()
	print(player.Name.." clicked (the first detector, parented to rig)")
end)

The morph code:

game.Players.PlayerAdded:Connect(function(p)
	p.Chatted:Connect(function(msg:string)
		if msg == "testmorph" then
			local char = game.ReplicatedStorage.StarterCharacter:Clone()
			char.Parent = workspace
			char:PivotTo(p.Character:GetPivot())
			p.Character:Destroy()
			p.Character = char
			local fix = script.CameraFix:Clone()
			fix.Parent = char
			fix.Enabled = true
			print("morphed "..p.Name)
		end
	end)
end)

If you’re wondering what CameraFix is, its a script i made that fixes the camera because when i set a new character, the camera doesnt get set to it (if you have any other ways to fix it please let me know)

--ServerScript in ServerScriptService
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(msg)
        if msg == "testmorph" then
            local oldChar = player.Character
            local newChar = game.ReplicatedStorage.StarterCharacter:Clone()
            newChar.Parent = workspace
            newChar:PivotTo(oldChar:GetPivot())
            
            -- Move all LocalScripts from old character to new one
            for _, scriptObj in pairs(oldChar:GetChildren()) do
                if scriptObj:IsA("LocalScript") then
                    scriptObj:Clone().Parent = newChar
                end
            end

            player.Character = newChar
            oldChar:Destroy()

            -- Fix camera
            local cam = workspace.CurrentCamera
            cam.CameraSubject = newChar:WaitForChild("Humanoid")
            cam.CameraType = Enum.CameraType.Custom

            print("Morphed "..player.Name)
        end
    end)
end)

im.. pretty sure you cant acess the client camera from the server, or am i wrong?

OH i think you meant like, the new code for the camera fix script?

Umm, no you’re right.. I rush too much sometime.

--LocalScript in StarterPlayerScripts or cloned into new character
local player = game.Players.LocalPlayer

player.CharacterAdded:Connect(function(char)
    local humanoid = char:WaitForChild("Humanoid")
    local cam = workspace.CurrentCamera
    cam.CameraSubject = humanoid
    cam.CameraType = Enum.CameraType.Custom
end)

Its fine*, take your time
also cloning it into the new character doesnt really work just so you know

Yeah, the more you know i guess

but really, is there a way to make it so scripts dont break when you dont use StarterCharacterScripts and set the .Character that you know?

or do i have to wait for someone else to (hopefully) answer my question

Well .. maybe :rofl:

Maybe an all out slightly twisted way..

LocalScript
--LocalScript in StarterPlayerScripts
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer

local function setupCharacter(character)
    -- Clone reusable LocalScripts
    for _, scriptObj in pairs(ReplicatedStorage.CharacterScripts:GetChildren()) do
        if scriptObj:IsA("LocalScript") then
            scriptObj:Clone().Parent = character
        end
    end

    -- Clone tools (optional)
    if ReplicatedStorage:FindFirstChild("CharacterTools") then
        for _, tool in pairs(ReplicatedStorage.CharacterTools:GetChildren()) do
            if tool:IsA("Tool") then
                tool:Clone().Parent = character
            end
        end
    end

    -- Fix camera
    local humanoid = character:WaitForChild("Humanoid")
    local cam = workspace.CurrentCamera
    cam.CameraSubject = humanoid
    cam.CameraType = Enum.CameraType.Custom
end

player.CharacterAdded:Connect(setupCharacter)
ServerScript
--ServerScript in ServerScriptService
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local function morph(player, newRig)
    local oldChar = player.Character
    newRig.Parent = workspace
    newRig:PivotTo(oldChar:GetPivot())
    player.Character = newRig
    oldChar:Destroy()
end

Players.PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(msg)
        if msg == "testmorph" then
            local newChar = ReplicatedStorage.StarterCharacter:Clone()
            morph(player, newChar)
            print("Morphed "..player.Name)
        end
    end)
end)

Well, it works.. atleast?
Thanks!