Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Only one player can morph and when you reset you can not morph anymore, what is the fix for this?

Asked by 2 years ago

As this title implies, once one player morphs no one else can morph and once that player resets they also will not get the morph anymore.

local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
local PlayBtn = game:GetService("StarterGui").ScreenGui.MainFrame.Confirm
local ChangeLoadout = ReplicatedStorage:WaitForChild("GiveLoadout")
local charactermodels = ServerStorage.CharacterModels




ChangeLoadout.OnServerEvent:Connect(function(player)
    local morph = player.Loadouts.loadout.Value
    local morphchosen = ServerStorage.CharacterModels:WaitForChild(morph)
    local morphname = morphchosen.Name
    if morph == morphname then
        morphchosen:PivotTo(player.Character:GetPivot())
        player.Character = morphchosen
        morphchosen.Parent = workspace
    end
end)

1 answer

Log in to vote
0
Answered by
Leamir 3138 Moderation Voter Community Moderator
2 years ago

Hello, thomas666666666666!

The problem with your code is that you are moving the morph you have in server storage to the player's character, you just need to clone it before doing it.

local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
local PlayBtn = game:GetService("StarterGui").ScreenGui.MainFrame.Confirm
local ChangeLoadout = ReplicatedStorage:WaitForChild("GiveLoadout")
local charactermodels = ServerStorage.CharacterModels




ChangeLoadout.OnServerEvent:Connect(function(player)
    local morph = player.Loadouts.loadout.Value
    local morphchosen = ServerStorage.CharacterModels:WaitForChild(morph)
    local morphname = morphchosen.Name
    if morph == morphname then
        local morphClone = morphchosen:Clone()
        morphClone :PivotTo(player.Character:GetPivot())
        player.Character = morphClone 
        morphClone .Parent = workspace
    end
end)

If this answers your question, please don't forget to mark it as the "Accepted Answer"

Ad

Answer this question