How to make a Refresh Command

I am wondering how to make a /refresh command for my game. I have successfully done this before, but the camera moves. Is there a way I can refresh a player’s character without the camera moving?

Thanks for your time!

What do you mean when you say the camera moves? You mean when your character refreshes, the camera should freeze in place?

When I refresh the character the player’s camera changes angles. I am hoping to make the camera stay in the same angle unless the player moves it manually.

Set the CameraType to scriptable, it shouldn’t change when the player respawns.

hmmm that doesn’t seem to be working. I may be doing it wrong. Here is my script v

local Command = "/re" or "/refresh"

workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(chr) 
		player.Chatted:Connect(function(msg)
			
			if msg:sub(1, Command:len()):lower() == Command:lower() then
				
				pcall(function()
					local Pos = player.Character:GetPrimaryPartCFrame()
					player:LoadCharacter()
					player.Character:SetPrimaryPartCFrame(Pos)
					if player.Character:FindFirstChild("ForceField") then
						player.Character["ForceField"]:Destroy()
					end
				end)
			end
		end)
	end)
end)

Gotcha.

I’m a little confused as to what you mean though. Does your game have a custom camera system?

If so, or you want to keep it stationary for another reason, you should probably use a remote function to do it as :LoadCharacter can only be called from the server.

local func = game:GetService('ReplicatedStorage').RemoteFunction
local players = game:GetService('Players')

players.PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(msg)
        if msg:sub(1, Command:len()):lower() == Command:lower() then
            func:InvokeClient(player) -- this will yield until it receives a response from the client
            player:LoadCharacter()
        end
    end
end

Then your local script,

local func = game:GetService('ReplicatedStorage').RemoteFunction

func.OnClientInvoke = function()
    workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
    return
end

The camera stays in place, although the character goes back to the spawn and I my camera doesnt go back to the character.

I’m a little confused as to what you mean haha. Do you want it to go back to their character once they spawn?

Sorry I just realized the wording on that message was trash. What I mean is the camera stays in the same place while the character goes back to spawn. I would love if the character would stay where it was before, simular to the /refresh command in TTD3.

Ohhh gotcha.

Not sure what that game is but I think it’s possible by using GetHumanoidDescriptionFromUserId.

Try this out:

local players = game:GetService('Players')

players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
	    if msg:sub(1, Command:len()):lower() == Command:lower() then
            local newHumanoidDescription = players:GetHumanoidDescriptionFromUserId(player.UserId)
            local character = player.Character or player.CharacterAdded:Wait()
            local humanoid = character:WaitForChild('Humanoid')
            humanoid:ApplyDescription(newHumanoidDescription)
		end
	end)
end)
3 Likes

Thank you so much, this works perfectly!

1 Like