So i have to make this character selection system where the player will click GUI and their starter charcter will change. I created a system but it seems to be very buggy and broken?
Heres the code if anyones interested
Client
repeat task.wait(1) until game:IsLoaded() task.wait(1)
local guiObject = script.Parent
local guiParent = script.Parent.Parent
local guiParent2 = script.Parent.Parent.Parent.MenuScreen
local event = game:GetService("ReplicatedStorage").CharacterSelectionEvent
local charCam = game.Workspace["Pyros Cameras"].CharacterCamera.RP
local currentCam = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer
local TS = game:GetService("TweenService")
guiObject.Activated:Connect(function(inputObject)
currentCam.CameraType = Enum.CameraType.Scriptable
guiParent.Enabled = false
guiParent2.Enabled = false
print("Character 1 Selected")
event:FireServer()
task.wait(.5)
-----------------
currentCam.CFrame = charCam.CFrame
local char = player.Character
local HRP = char.HumanoidRootPart
local hum = char.Humanoid
local tweem = TS:Create(currentCam, TweenInfo.new(1), {CFrame = HRP.CFrame})
tweem:Play()
tweem.Completed:Connect(function()
currentCam.CameraSubject = hum
currentCam.CameraType = Enum.CameraType.Custom
end)
end)
Server
local event = game:GetService("ReplicatedStorage").CharacterSelectionEvent
local RepSto = game:GetService("ReplicatedStorage")
event.OnServerEvent:Connect(function(plr)
print(plr.Name, "has chosen Character 1!")
local plrGUI = plr.PlayerGui
local char = plr.Character
local newChar = RepSto.StarterCharacters:WaitForChild("CamiloCharacter"):Clone()
local oldCF = char:GetPrimaryPartCFrame()
newChar.Name = "StarterCharacter"
newChar.Parent = game.Workspace
newChar:SetPrimaryPartCFrame(oldCF)
plr.Character = newChar
plrGUI.MenuScreen.Enabled = false
plrGUI.MenuScreen.Background["Play!"]["Play Script"].Disabled = true
char:Destroy()
end)
The scripts shown above “work” but there are a few bugs and i dont exactly know what the issue is.
- If a player tries to reset they get stuck and dont reset
- Animations wont play
With this being said, i wonder if my way of going about it entirely was wrong. So my question is how do i create an effective character selection system?
Help is greatly appriciated, thank you for your time