Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I revert a changed userId back to original userId?

Asked by 3 years ago

hello, I'm trying to make a script that when a sword hits you, your character turns into a certain players character through userid, I have all that working but after a certain amount of time I want the player to change back to their original character/userid but I can't figure out how to do that. any help would be appreciated

debounce = true 
game.Players.PlayerAdded:Connect(function(player)
    script.Parent.Touched:Connect(function()
        if debounce == true then
            debounce = false
            player.CharacterAppearanceId = 261
            player:LoadCharacter()
            debounce = true 
        end
    end)
end)
0
Before changing their id. Save their previous appearance id. Maybe that works Soban06 410 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Well, you can just create a NumberValue and put it in Folder in ServerStorage on Player join. You can name it as the player's name and its value a the player's UserId. And on player remove, you can delete that NumberValue. Here's an example, that you can use:

--//Functions
local function PlayerJoin(player)
    if game.ServerStorage:FindFirstChild(player.Name) then return end -- A double check 'if' statement whether the player name already existed in ServerStorage
    local NumValue = Instance.new("NumberValue") -- Creating a NumberValue
    NumValue.Parent = game.ServerStorage.Folder -- Parenting it to the Folder in Server Storage
    NumValue.Value = player.CharacterAppearanceId -- Setting its Value to the player's appearance ID
--  NumValue.Value = player.UserId  [If you really want to get the original player's character appearance, then get the player's UserId]
    NumValue.Name = player.Name -- Setting its Name to player's name
end

local function PlayerLeave(player)
    if game.ServerStorage.Folder:FindFirstChild(player.Name) then -- Checking whether the NumberValue have the player's name who is leaving
        local plr = game.ServerStorage.Folder:FindFirstChild(player.Name) -- Assigning a variable for easiness
        plr:Destroy() -- Deleting the Value
    end
end

--//Main
game.Players.PlayerAdded:Connect(PlayerJoin)
game.Players.PlayerRemoving:Connect(PlayerLeave)

And now you have a method to get the original player's UserId, then you can change the player's character to back to original.

Lemme know if it helps!

0
Alternatively, if you're only working with CharacterAppearanceId, setting this value to 0 will automatically use the default appearance for a player. Optikk 499 — 3y
Ad

Answer this question