I devs, today I would to make a switching character button like in Batman Lego. But I want to know how I can change the character, how to found the new Camera position and why my ScreenGui is deleted when I click on the button.
Is in a LocalScript (ClientScript for the close friends like me )
--< Services
local PlayerService = game:GetService('Players')
local RStorageService = game:GetService('ReplicatedStorage')
local TweenService = game:GetService('TweenService')
--< Variables
local Player = PlayerService.LocalPlayer
local PlayerGui = Player:WaitForChild('PlayerGui')
local CurrentCamera = workspace.CurrentCamera
local OtherCharacter = workspace.NPC
local OriginalCharacter = Player.Character
local Viewer = OriginalCharacter
local ActualTween = nil
--< Events
PlayerGui:WaitForChild('ScreenGui'):WaitForChild('Frame'):WaitForChild('Button').MouseButton1Click:Connect(function()
Viewer = Viewer == OriginalCharacter and OtherCharacter or OriginalCharacter -- Condition
print(Viewer.Name)
if ActualTween ~= nil then
ActualTween:Cancel()
end
Player.Character = Viewer
CurrentCamera.CameraType = Enum.CameraType.Scriptable
ActualTween = TweenService:Create(CurrentCamera, TweenInfo.new(1), {CFrame = Viewer:FindFirstChild('Head').CFrame + Vector3.new(0, 2, 0)})
ActualTween:Play()
ActualTween.Completed:Connect(function()
CurrentCamera.CameraType = Enum.CameraType.Custom
CurrentCamera.CameraSubject = Viewer
ActualTween = nil
end)
end)
Just a random thought. Your not actually running the tween your just creating it. Try ActualTween:Play() For changing your character there are multiple paths you can take which I don’t know much about but you could change their ApperanceCharacterId and then respawn them. Other than that I don’t understand the other question
Yes lol now when I do a play it’s work for the camera, but I don’t want to change their appearance. Check the Gyazo, when I click on the button, the ScreenGui is removed of my PlayerGui, why ?! And when I play with the NPC It lag. Test yourself: SwitchingCharacter.rbxl (44.7 KB)
Yes thank you, but I can’t use that as reference because I dont want create a clone and teleport myself by him, I want to control another character directly. And this script doesn’t controle the other Character but just inverse the position.
Well, you can set-up the script and manage it so when you teleport to the other NPC, the NPC will morph as your character, and you will morph as him. And i highly recommend you to use this, what you are trying to achieve is very hard, and i recommend you this alot. And when you get more experience and resources to create this, you can create it. Same as i’m doing with my game.
Thank you again for your answer, I understand the complexity of my project but I want to complete it, I have the knowledge to create what you offer me but I didn’t make that because I don’t want it means I would not have to make this post. If we can talk about another problem now beside the other thing it will be great!
I will soon succeed, simply I have to find out why the NPC does not move and why the PlayerGUI is removed when I click on it. Then finnaly I have to find the right camera position. If nobody is able to answer me, it does not matter, as you say one day I will be able to make it with more knowledge but maybe I can learn them here!
Well, as i see in the script, there’s not any code about movement, so the player will keep it’s movement and will not be changed, maybe i forgot to read something in the script, but as i can see, nothing is in the script about movement.
On clicking:
Condition
Tween cancels if it’s not nil.
Character is the viewer.
Camera is set to the other character.
Tween plays.
And other stuff which is not needed to get explained.
I think nothing there is changing/modifying the movement.
If you want see the entire project, I’ve sent that in the commentaries, download it if you want understand more but I think you doesn’t have the necessary knowledge to answer my questions. Thanks for trying.