What needs to be achieved?
- A ScreenGui button that fires a Remote Event. Which then shall change the User who presses said button to the specific class on their team using the Remote Event.
Whats the issue?
- When the ScreenGui button is pressed, it destroys the Users character model.
Attempted Fixes
- Trying to use the “StarterCharacter”. Which then leads to the User constantly being said character.
Now with the code used for this (pretty simple yet doesn’t work.)
ServerScriptService/Remote Event OnSeverEvent function
local Rep = game:GetService('ReplicatedStorage')
game.ReplicatedStorage.Character.OnServerEvent:Connect(function(player, Team ,Class)
local ClassCloned = Rep[Team][Class]:Clone()
player.Character = ClassCloned
end)
ScreenGui Button Script
local Rep = game:GetService('ReplicatedStorage')
local Event = Rep:FindFirstChild("Character")
script.Parent.TestFunction.Activated:Connect(function()
Event:FireServer("Team Destroy", "Less")
end)
1 Like
In the server script, try setting the parent of “ClassCloned”.
Example:
game.ReplicatedStorage.Character.OnServerEvent:Connect(function(player, Team ,Class)
local ClassCloned = Rep[Team][Class]:Clone()
ClassCloned.Parent = workspace
player.Character = ClassCloned
end)
Now the model appears and is moveable.
But the Player does not follow the Models Head (if that makes sense)
When you say change the user, do you mean morph the player character?
Yes, morphing the user is easier than using StarterCharacter(because theres multiple)
From the server, you need a way to tell the client to change the camera. You could try re-firing the event and passing the custom character as an argument.
local Rep = game:GetService('ReplicatedStorage')
local characterEvent = Rep:WaitForChild("Character") -- Declare a variable for the event
characterEvent.OnServerEvent:Connect(function(player, Team ,Class)
local ClassCloned = Rep[Team][Class]:Clone()
ClassCloned.Parent = workspace
player.Character = ClassCloned
characterEvent:FireClient(player, ClassCloned)
end)
In the local script you should try changing the CameraType to Enum.CameraType.Fixed and the CameraSubject to the PrimaryPart of your custom character.
local Rep = game:GetService('ReplicatedStorage')
local Event = Rep:FindFirstChild("Character")
local camera = workspace.CurrentCamera
script.Parent.TestFunction.Activated:Connect(function()
Event:FireServer("Team Destroy", "Less")
end)
Event.OnClientEvent:Connect(function(customCharacter)
camera.CameraType = Enum.CameraType.Fixed
camera.CameraSubject = customCharacter.PrimaryPart
end)