This script is supposed to create a model when a player enters the game, create another in a second location when someone else joins and remove the appropriate model when they leave the game. I'm exhausted and my knowledge of this syntax is limited. Send help, the model's appear fine but when a play leaves the game neither of them will disappear
function CreateShip(xcoord,ycoord,zcoord)
local NewShip = workspace.Ship:clone()
NewShip.Parent = game.Workspace
NewShip:makeJoints()
NewShip:MoveTo(Vector3.new(xcoord,ycoord,zcoord))
NewShip.Name = AltName
end
game.Players.PlayerAdded:connect(function(player)
if workspace.Ship.Ship1Val.Value == false then
local AltName = player.Name
CreateShip(-1005,36,470)
workspace.Ship.Ship1Val.Value = true
workspace.Ship.Owner1.Value = player.Name
elseif workspace.Ship.Ship2Val.Value == false then
local AltName = player.Name
CreateShip(-1005,36,450)
workspace.Ship.Ship2Val.Value = true
workspace.Ship.Owner2.Value = player.Name
end
end)
game.Players.PlayerRemoving:connect(function(p)
if p.Name == workspace.Ship.Owner1.Value then
local AltName = p.Name
local ShipName = workspace.Ship:WaitForChild(AltName)
ShipName:remove()
workspace.Ship.Owner1.Value = nil
workspace.Ship.Ship1Val.Value = false
elseif p.Name == workspace.Ship.Owner2.Value then
local AltName = p.Name
local ShipName = workspace.Ship:WaitForChild(AltName)
ShipName:remove()
workspace.Ship.Owner2.Value = nil
workspace.Ship.Ship2Val.Value = false
end
end)
I suspect it's an issue with naming the cloned models in the first place as I cannot refer to them easily, however I have no idea how to approach this problem and have tried multiple varying efforts to no avail Many Thanks, Sam

1 comment
I'm aware the example code doesn't work. The amount of changes I'd have to make to the script would have the end result as well.