#How to make sure the player respawns back with the custom character?

17 messages · Page 1 of 1 (latest)

narrow solar
#
local function transform(Player, Transforming_Player, mssg, count)
    print(Transforming_Player.Name)
    print(mssg)
    if mssg == "Sphere_Transformation" then
        print("count is: " .. count)
        if count == 1 then
            local spawneffect = game.ReplicatedStorage:WaitForChild("SpawnEffect")
            print("mssg is: " .. mssg)
            local Sphere_Model = game.Workspace:WaitForChild("Circle")
            local SphereClone = Sphere_Model:Clone()
            local Animator = Instance.new("Animator", Sphere_Model.Humanoid)
            local char = Transforming_Player.Character
            SphereClone.Name = Transforming_Player.Name
            SphereClone.HumanoidRootPart.CFrame = Transforming_Player.Character.HumanoidRootPart.CFrame
            Transforming_Player.Character = SphereClone
            SphereClone.Parent = game.Workspace

            print("Transformation is done.")
            
            local spawnclone = spawneffect:Clone()
            spawnclone.Parent = SphereClone.HumanoidRootPart
            spawnclone.CFrame = SphereClone.HumanoidRootPart.CFrame - Vector3.new(0, 4.296, 0)
            spawnclone.WeldConstraint.Part0 = SphereClone.HumanoidRootPart
            spawnclone.WeldConstraint.Part1 = spawnclone

            task.wait(1.5)

            SphereClone.HumanoidRootPart:SetNetworkOwner(Transforming_Player)
            Transforming_Player:SetAttribute("Transformed", true)

            spawnclone:Destroy()
            return true, SphereClone, count  -- Return the current count

        elseif count == 2 then
            Transforming_Player:LoadCharacter()
            Transforming_Player:SetAttribute("Transformed", false)
            count = 0  -- Reset count on the server side
            return false, nil, count  -- Return the reset count to the client
        end

game.ReplicatedStorage.Remotes.TransformationRF.OnServerInvoke = transform

Serverscript

#
local SoundEffect = game.ReplicatedStorage:WaitForChild("SoundEffect")
local GUIButton = script.Parent
local camera = workspace.CurrentCamera

local animationID = "rbxassetid://18710085699"
local runningAnimation = Instance.new("Animation")
runningAnimation.AnimationId = animationID
local humanoid
local player
local runningTrack
local spawneffect = game.ReplicatedStorage:WaitForChild("SpawnEffect")
local count = 0
local spawnclone

GUIButton.MouseButton1Down:Connect(function()
    count += 1
    print("Button Clicked!")
    local RF = game.ReplicatedStorage.Remotes.TransformationRF
    local PlayerTransformedBool, New_Character, UpdatedCount = RF:InvokeServer(game.Players.LocalPlayer, "Sphere_Transformation", count)

    -- Update the count with the value received from the server
    count = UpdatedCount

    if PlayerTransformedBool == true then
        print(PlayerTransformedBool)
        camera.CameraSubject = New_Character.Humanoid
        SoundEffect:Play()

        local humanoid = New_Character:WaitForChild("Humanoid")
        local player = game.Players.LocalPlayer
        local runningTrack = humanoid:LoadAnimation(runningAnimation)
        print("Player transformed!")

        New_Character.Humanoid.Running:Connect(function(speed)
            if speed > 0 then
                if not runningTrack.IsPlaying then
                    runningTrack:Play()
                end
                runningTrack:AdjustSpeed(1)
            else
                if runningTrack.IsPlaying then
                    runningTrack:AdjustSpeed(0)
                end
            end
        end)

        print("Transformation/Animation ran.")
    end
end)

localscript

scenic laurel
#

have u tried using a detect where if the player spawns, his avatar changes to the custom character?

#

i tjink its called Player.CharacterAdded

#

so that everytime the player spawns again, the avatar changes to the custom one

narrow solar
# scenic laurel inside server script*

i tried doing

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function()
        if player:GetAttribute("Transformed") and player:GetAttribute("Red") then -- Circle
            local Circle_Model = game.Workspace:WaitForChild("Circle")
            local CircleClone = Circle_Model:Clone()
            CircleClone.Name = player.Name
            CircleClone.HumanoidRootPart.CFrame = player.Character.HumanoidRootPart.CFrame
            player.Character = CircleClone
            CircleClone.Parent = game.Workspace
        elseif player:GetAttribute("Transformed") and player:GetAttribute("Blue") then -- Square
            local Square_Model = game.Workspace:WaitForChild("Square")
            local SquareClone = Square_Model:Clone()
            SquareClone.Name = player.Name
            SquareClone.HumanoidRootPart.CFrame = player.Character.HumanoidRootPart.CFrame
        end
    end)
end)

But its sooo buggy + the animation linked to the custom character doesnt work!

scenic laurel
#

u dont need to write Playeradded twice

#

one player added is alrdy enough

narrow solar
#

but playeradded is for when the player joins the game

scenic laurel
#

yea

long starBOT
#

studio** You are now Level 2! **studio

scenic laurel
#

doesnt it detect it alrdy?

#

oh mb

#

what part of it is buggy?

narrow solar