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

Problem with my round script?

Asked by
Relatch 550 Moderation Voter
10 years ago

No errors, but it shows who won for about 0.1 seconds and then goes back to the "Round, please wait". What did I do wrong?

Award = 10
Award2 = 5
local gui = game.Workspace.Part1.v.z

game.Players.PlayerAdded:connect(function(plr)
    local leaderstats = Instance.new("IntValue")
    leaderstats.Name = "leaderstats"

    local points = Instance.new("IntValue")
    points.Name = "Points"

    points.Parent = leaderstats
    leaderstats.Parent = plr
end)

function Fight()
    for _, player in pairs(game.Players:GetPlayers()) do
        if player and player.Character then
            local humanoid = player.Character:WaitForChild("Humanoid")
            humanoid.MaxHealth = 10000
            humanoid.Health = 10000
        end
    end
    for i = 15, 0, -1 do
        if i <= 9 then
            gui.Text = "Intermission (0:0"..i..")"
        else
            gui.Text = "Intermission (0:"..i..")"
        end
        wait(1)
    end
    gui.Text = "Now choosing duelers."
    wait(5)

    local plrs = game.Players:GetPlayers()
    local p1 = plrs [math.random(1, #plrs)]
    local p2 = plrs [math.random(1, #plrs)]
    ended = false
    repeat p2 = plrs[math.random(1, #plrs)] until p2 ~= p1

    gui.Text = p1.Name.. " and " ..p2.Name.. " have been chosen to duel."
    wait(3)

    p1.Character.Torso.CFrame = CFrame.new(147.5, 14.6, 15) 
    p2.Character.Torso.CFrame = CFrame.new(147.5, 14.6, -59)

    local sword1 = game.ServerStorage.Sword1:Clone()
    sword1.Parent = p1.Backpack

    local sword2 = game.ServerStorage.Sword2:Clone()
    sword2.Parent = p2.Backpack

    for i = 3, 0, -1 do
        gui.Text = "Starting in " ..i
        p1.Character.Humanoid.WalkSpeed = 0

        p2.Character.Humanoid.WalkSpeed = 0
        wait(1)
    end

    p1.Character.Humanoid.MaxHealth = 100
    p1.Character.Humanoid.Health = 100
    p1.Character.Humanoid.WalkSpeed = 16

    p2.Character.Humanoid.MaxHealth = 100
    p2.Character.Humanoid.Health = 100
    p2.Character.Humanoid.WalkSpeed = 16

    for i = 30, 0, -1 do
        gui.Text = "Round, please wait (0:"..i..")"
        if i <= 9 then
            gui.Text = "Round, please wait (0:0"..i..")"
        end
        wait(1)
        p1.Character.Humanoid.Died:connect(function()
            p2.leaderstats.Points.Value = p2.leaderstats.Points.Value + Award
            gui.Text = p2.Name.." has won."
            game:GetService("PointsService"):AwardPoints(p2.userId,150)
            wait(3)
            ended = true
        end)
        if ended == true then
            break
        end
        p2.Character.Humanoid.Died:connect(function()
            p1.leaderstats.Points.Value = p1.leaderstats.Points.Value + Award
            gui.Text = p1.Name.." has won."
            game:GetService("PointsService"):AwardPoints(p1.userId,150)
            wait(3)
            ended = true
        end)
        if ended == true then
            break
        end
    end
    p1.Character.Torso.CFrame = CFrame.new(190.2, 3.8, -25.6) 
    p1.Character.Humanoid:UnequipTools()
    p1.Backpack:ClearAllChildren()

    p2.Character.Torso.CFrame = CFrame.new(184.2, 3.8, -25.6)
    p2.Character.Humanoid:UnequipTools()
    p2.Backpack:ClearAllChildren()
end

while true do
    if game.Players.NumPlayers > 1 then
        wait(1)
        Fight()
    elseif game.Players.NumPlayers == 1 then
        gui.Text = "Waiting for 2 or more players."
    end
    wait()
end
0
Maybe on line 90 where you said "ended = true" and then it said "if ended == true then raystriker6707 30 — 10y
0
Maybe you should try adding a wait(3) at the very end (before you clear their weapons) of the function or right after the function is called. Tkdriverx 514 — 10y
0
@Tkdriverx, could you answer in a comment so I understand better? Relatch 550 — 10y

1 answer

Log in to vote
-1
Answered by 10 years ago

Function connected by events dont make delays in the script. Try doing this:

if player.Humanoid.Health = 0 then
    --Code
end
0
That's not even the question.. Relatch 550 — 10y
Ad

Answer this question