Hello! This is similar to something I've asked previously and I've edited it accordingly and tried out more things but it just refuses to work! Any ideas?
This code is supposed to build an item when someone joins the game, at certain coordinates (which works fine) but it is also supposed to remove it when the appropriate player leaves the game. I think the trouble is, I cannot call on the ships and I'm not sure how to name clones or refer to them later on in order to remove them.
function CreateShip(xcoord,ycoord,zcoord,AltName)
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
CreateShip(-1005,36,470,Ship01)
workspace.Ship.Ship1Val.Value = true
workspace.Ship.Owner1.Value = player.Name
elseif workspace.Ship.Ship2Val.Value == false then
CreateShip(-1005,36,450,Ship02)
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 ShipName = workspace.Ship:WaitForChild(Ship01)
ShipName:remove()
workspace.Ship.Owner1.Value = nil
workspace.Ship.Ship1Val.Value = false
elseif p.Name == workspace.Ship.Owner2.Value then
local ShipName = workspace.Ship:WaitForChild(Ship02)
ShipName:remove()
workspace.Ship.Owner2.Value = nil
workspace.Ship.Ship2Val.Value = false
end
end)

1 comment
Thankyou! It was just syntax errors, I took more care and I've finally got it working the way it should