Hey, I'm trying to make a game where you have 4 characters at all times, where you can switch between them. When you press for example "J" you become one custom character and if you press it again you come back to your Roblox character again. But I'm having a problem where if you press "J" twice the game activates both scripts. I only want the script to be able to run when I'm not currently that character. My code does have some unused parts from testing around.
local uis = game:GetService("UserInputService")
local mFrame = script.Parent.MenuFrame
local player = game:GetService("Players").LocalPlayer
local remote = game.ReplicatedStorage.Remotes.SwitchCharacter
local CurCharacter = game.Players.LocalPlayer.Character
local NewCharacter = game.Workspace.TestDum
local camera = workspace.CurrentCamera
local keycode = Enum.KeyCode.J
local ImagePos = script.Parent.MenuFrame.Position
local origin = script.Parent
uis.InputBegan:Connect(function(input,gameProcessedEvent)
if input.KeyCode == keycode then
print("fired")
remote:FireServer(CurCharacter, NewCharacter,keycode, ImagePos, origin)
camera.CameraSubject = NewCharacter
end
end)
These are the local scripts for the custom characters so it's used 3 times for the 3 different characters
local remote = game.ReplicatedStorage.Remotes.SwitchCharacter
local CharacterSwitch =require(game.ServerScriptService.SwitchCharacter)
local key = nil
local origin1 = nil
local function SwitchCharacter(player, CurCharacter, NewCharacter,keycode, ImagePos, origin)
print(CurCharacter,NewCharacter)
if key == keycode then
remote:FireClient(player, keycode, ImagePos, NewCharacter)
else
if origin == "char1" then
CurCharacter.Archivable= true
local CurAi = player.Character:Clone()
--local CurMovement = NewCharacter.MoveScript:Clone()
CurAi.Parent = workspace
--CurMovement.Parent = CurAi
--NewCharacter.MoveScript:Destroy()
player.Character = NewCharacter
key = keycode
end
end
end
remote.OnServerEvent:Connect(SwitchCharacter)
This server script is where you actually change character
local uis = game:GetService("UserInputService")
local mFrame = script.Parent.MenuFrame
local player = game:GetService("Players").LocalPlayer
local remote = game.ReplicatedStorage.Remotes.SwitchCharacter
local CurCharacter = game.Players.LocalPlayer.Character
local New = nil
local camera = workspace.CurrentCamera
local key = nil
local function idfk(Keycode, Imagepos,NewCharacter)
print(Keycode)
if script.Value.Value == false then
script.Parent.MenuFrame.Visible = true
key = Keycode
print(key)
script.Parent.MenuFrame.Position = Imagepos
New = NewCharacter
script.Value.Value = true
elseif script.Value.Value == true then
script.Parent.MenuFrame.Visible = false
script.Value.Value = false
end
end
remote.OnClientEvent:Connect(idfk)
uis.InputBegan:Connect(function(input,gameProcessedEvent)
if input.KeyCode == key then
remote:FireServer(New, CurCharacter)
end
end)
this is the local script where you can change back to your original character
I'm sorry that the code is a messy, but I hope that it shows what I'm trying to do so you can teach me what I need to implement the feature :)

2 comments
you can just add Script.Disabled = true after you change character
hahaha I thought i had done that but I was accidentally disabling the parent of the script which doesnt disable the script. but it worked when disabling the script, I feel really dumb now since that was the first things i tested but thanks for motivating me to try it again, and helping me! :)