Need help,
I’m creating my first game and I don’t know which of these two scripts is more recommended for (morph),
and how do I make the player continue with the character after death. Thanks!
local players = game:GetService"Players"
local starterPlayer = game:GetService"StarterPlayer"
local replicated = game:GetService"ReplicatedStorage"
local morphRemote = replicated.MorphRemote
local morphsFolder = replicated.MorphsFolder
local function onMorphRemoteFired(player, model)
players.CharacterAutoLoads = false
local modelClone = model:Clone()
modelClone.Parent = starterPlayer
player:LoadCharacter()
modelClone:Destroy()
players.CharacterAutoLoads = true
for _, _player in ipairs(players:GetPlayers()) do
if _player ~= player then
if not _player.Character then
_player:LoadCharacter()
end
end
end
end
morphRemote.OnServerEvent:Connect(onMorphRemoteFired)
local tweens = game:GetService"TweenService"
local replicated = game:GetService"ReplicatedStorage"
local morphRemote = replicated:WaitForChild"MorphRemote"
local morphGui = script.Parent
local toggleButton = morphGui:WaitForChild"ToggleButton"
local morphFrame = morphGui:WaitForChild"MorphFrame"
local morphsFrame = morphFrame:WaitForChild"MorphsFrame"
local toggle = true
local debounce = false
local function onToggleButtonClicked()
if debounce then return end
debounce = true
toggle = not toggle
local direction = if toggle then "In" else "Out"
local position = if toggle then 0 else -0.3
local tween = tweens:Create(morphFrame, TweenInfo.new(0.5, Enum.EasingStyle.Quint, Enum.EasingDirection[direction]), {Position = UDim2.new(position, 0, 0.4, 0)})
tween:Play()
tween.Completed:Wait()
toggleButton.Text = if toggle then "<" else ">"
debounce = false
end
toggleButton.MouseButton1Click:Connect(onToggleButtonClicked)
local function onMorphButtonClicked(morphButton)
local morphFrame = morphButton.Parent
local objectValue = morphFrame:FindFirstChild"Value"
if objectValue then
if objectValue.Value then
morphRemote:FireServer(objectValue.Value)
end
end
end
for _, morphFrame in ipairs(morphsFrame:GetChildren()) do
if morphFrame:IsA"Frame" then
local morphButton = morphFrame:WaitForChild"MorphButton"
morphButton.MouseButton1Click:Connect(function()
onMorphButtonClicked(morphButton)
end)
end
end
--Remote Event
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Load = ReplicatedStorage.Load
local ChangeChar = ReplicatedStorage.ChangeChar
--On Event Functions
game:GetService("Players").PlayerAdded:Connect(function(Player)
local Morph = Instance.new("StringValue", script)
Morph.Name = Player.UserId .. "'s Morph"
Morph.Value = "DefaultAvatar"
end)
Load.OnServerEvent:Connect(function(Player, PlayerCF)
if script[Player.UserId .. "'s Morph"].Value ~= "DefaultAvatar" then
script[Player.UserId .. "'s Morph"].Value = "DefaultAvatar"
Player:LoadCharacter()
Player.Character.LowerTorso.CFrame = Player
end
end)
ChangeChar.OnServerEvent:Connect(function(Player, Character,Morph, PlayerCF)
local Humanoid = Character:WaitForChild("Humanoid")
if script[Player.UserId .. "'s Morph"].Value ~= Morph.Name then
script[Player.UserId.. "'s Morph"].Value = Morph.Name
local A = Morph:Clone()
A.Name = Player.Name
Player.Character = A
A.Parent = game.Workspace
Player.Character:WaitForChild("LowerTorso").CFrame = PlayerCF
end
end)
--Remote Event
local ChangeChar = game:GetService("ReplicatedStorage").ChangeChar
--Variables
local Player = game:GetService("Players").LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--Mouse Click Function
script.Parent.MouseButton1Click:Connect(function()
local Character = Player.Character
local Morph = ReplicatedStorage.RealPlayers[script.Parent.Name]
local PlayerCF = Character.LowerTorso.CFrame
ChangeChar:FireServer(Character,Morph,PlayerCF)
end)