local rs = game:GetService("ReplicatedStorage")
local event = rs.Events.UI.MainMenu.Deploy
game.Players.PlayerAdded:Connect(function(plr) -- changed this line
local char = plr.Character
local oldPosition = char.PrimaryPart
local newCharacter = game:GetService("ReplicatedFirst")["Character Manager"].Character:Clone()
local newAnimate = game:GetService("ReplicatedFirst")["Character Manager"].AnimatorCharacter:Clone()
newAnimate.Name = "Animate"
newCharacter.Name = plr.Name
newCharacter:PivotTo(oldPosition.CFrame)
char:Destroy()
plr.Character = newCharacter
char = plr.Character
newCharacter.Parent = workspace
newAnimate.Parent = newCharacter
local humanoid = newCharacter.Humanoid
print(0)
event:FireClient(plr, humanoid)
print(1)
end)
game.Players.PlayerAdded:Connect(function(plr) also gets the player when somebody joins the game.
OnServerEvent wont work unless you fire it in your localscript. But I guess it will also work if you replace the serverscript with the script above. It fires when the player joins the game and then it will fire the event to the client.
Player joins the game → Event fires to the client → The localscript should fire
If I didn´t get it wrong and your button is a Gui and not a button with a Clickdetector in the workspace then place this localscript in your ButtonGui:
Localscript:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage.UI.MainMenu.Deploy
script.Parent.MouseButton1Click:Connect(function(Player)
print(1)
game.Workspace.Camera.CameraSubject = Player.Character.humanoid
game.Workspace.Camera.CameraType = Enum.CameraType.Custom
Event:FireServer() -- I dont think there should be anything inside FireServer()
end)
like this:
if this works delete your current Localscript and everything should be working fine
This script fires like this:
Player presses the Gui Button → It fires the Event to the Server → The Serverscript does the other stuff
oh and dont forget to replace the serverscript with this:
Serverscript:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage.Events.UI.MainMenu.Deploy
Event.OnServerEvent:Connect(function(plr)
local char = plr.Character
local oldPosition = char.PrimaryPart
local newCharacter = game:GetService("ReplicatedFirst")["Character Manager"].Character:Clone()
local newAnimate = game:GetService("ReplicatedFirst")["Character Manager"].AnimatorCharacter:Clone()
newAnimate.Name = "Animate"
newCharacter.Name = plr.Name
newCharacter:PivotTo(oldPosition.CFrame)
char:Destroy()
plr.Character = newCharacter
char = plr.Character
newCharacter.Parent = workspace
newAnimate.Parent = newCharacter
end)