function finish() if #alive == 1 then message = Instance.new("Message",game.Workspace) message.Text = "The winner was "..alive[1].Name alive[1].leaderstats.Wins.Value = alive[1].leaderstats.Wins.Value+1 data:SetAsync(alive[1].userId.."_data",alive[1].leaderstats.Wins.Value) alive[1].Character:MoveTo(game.Workspace.SpawnLocation.Position) for u, o in pairs(game.Players:GetPlayers()) do o.Backpack:findFirstChild("FingerLazers"):Destroy() end table.remove(alive,1) wait(2) message:Destroy() wait() message:Destroy() regenmap() done = true end end
This should work, I get no errors but it isn't working. The FingerLazers is not destroying from my backpack and the game never ends
EDIT:
function finish() if #alive == 1 then message = Instance.new("Message",game.Workspace) message.Text = "The winner was "..alive[1].Name alive[1].leaderstats.Wins.Value = alive[1].leaderstats.Wins.Value+1 data:SetAsync(alive[1].userId.."_data",alive[1].leaderstats.Wins.Value) alive[1].Character:MoveTo(game.Workspace.SpawnLocation.Position) table.remove(alive,1) wait(2) message:Destroy() wait() message:Destroy() end regenmap() done = true end
This was the old code before my friend tried to fix it for me which worked absolutely fine with no troubles until I decided I wanted to add the lazer, now when I try and remove it from the player's backpack it doesn't work, and the game won't end.
I highly recommend tabbing your code. It makes it much easier to read.
I don't see anything wrong with the code you posted in particular.
Here are some other things to check, though:
1) Is alive
being updated correctly? You refer to to alive[1].Character:MoveTo
but this will trigger an error if alive[1].Character
is nil
, that is, they fell off the map or other various things.
2) Is FingerLazers
the exact spelling, punctuation, and spacing of the tool name?
3) Is every player guaranteed to have a FingerLazers
object in their backpack? Even if they've already lost the game, or just recently joined? You don't do a check here that there is indeed a FingerLazers
object, and referring to :Destroy
on nil
(the return of findFirstChild
when there is no such child) will error.
Have you tried testing this code in a Test Server from Studio so that you can read errors? That is an excellent debugging process.