Answered by
pwx 1581
5 years ago Edited 5 years ago
First things first, let's start with the setup to get everything ready before coding.
Step-up
1a. Create a RemoteEvent, put it in ReplicatedStorage.
1b. Name it whatever you want, preferably to something that reminds you what it's for such as 'MorphRemote'.
2a. Create a LocalScript, preferably put it in the UI you have made.
3a. Create a ServerScript, place it in ServerScriptService.
4a. Place your morph elsewhere, such as ServerStorage.
LocalScript
02 | Player = game.Players.LocalPlayer |
03 | Mouse = Player:GetMouse() |
06 | RS = game:GetService( 'ReplicatedStorage' ) |
09 | Remote = RS:WaitForChild( 'MorphRemote' ) |
14 | Button.MouseButton 1 Click:Connect( function () |
ServerScript
02 | RS = game:GetService( 'ReplicatedStorage' ) |
03 | SS = game:GetService( 'ServerStorage' ) |
06 | Remote = RS:WaitForChild( 'MorphRemote' ) |
07 | Morph = SS:WaitForChild( 'Morphy' ) |
10 | function MorphHandler(Player) |
11 | local Character = Player.Character or Player.CharacterAdded:Wait() |
13 | if Character:WaitForChild( 'UsingMorph' ).Value = = true then |
14 | Character.UsingMorph.Value = false |
15 | for _,limb in pairs (Character:GetChildren()) do |
16 | if limb:IsA( 'BasePart' ) then |
21 | if Character:FindFirstChild( 'Chest' ) then Character.Chest:Destroy() end |
22 | if Character:FindFirstChild( 'Arm1' ) then Character.Arm 1 :Destroy() end |
23 | if Character:FindFirstChild( 'Arm2' ) then Character.Arm 2 :Destroy() end |
24 | if Character:FindFirstChild( 'Leg1' ) then Character.Leg 1 :Destroy() end |
25 | if Character:FindFirstChild( 'Leg2' ) then Character.Leg 2 :Destroy() end |
26 | elseif Character:WaitForChild( 'UsingMorph' ).Value = = false then |
27 | Character.UsingMorph.Value = true |
28 | for _,limb in pairs (Character:GetChildren()) do |
29 | if limb:IsA( 'BasePart' ) then |
34 | local modelname = Morph:Clone() |
44 | Remote.OnServerEvent:Connect(MorphHandler) |