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

Another gamebreaker? Sigh

Asked by 10 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
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.

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

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:MoveTobut 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.

0
1) Yes it is, 2) Yep 3) There should only be 1 player that has it at the time of it finishing, because players would have died so they would lose it upon respawn. User#2154 0 — 10y
Ad

Answer this question