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

My sword fighting script is not working?

Asked by
Relatch 550 Moderation Voter
10 years ago
function ChooseDuelers()
    repeat wait() until game.Players.NumPlayers >=2
    for i = 20, 0, -1 do
        script.Lobby:Play()
        h = Instance.new("Hint",workspace)
        h.Text = "Round starting in: " ..i
        wait(1)
        h:Destroy()
    end
    local Players=Game.Players:GetPlayers() 
    local Chosen1, Chosen2 = math.random(1, #Players), 0
    repeat Chosen2 = math.random(1, #Players) until Chosen2 ~= Chosen1
    m = Instance.new("Message",workspace)
    m.Text = Players[Chosen1].Name.. " and " ..Players[Chosen2].Name.. " have been chosen!"
    wait(3)
    Players[Chosen1].Character:MoveTo(Vector3.new(-82.5, 0.59, 19))
    Players[Chosen2].Character:MoveTo(Vector3.new(-82.5, 0.59, -25))
    m.Text = "Duelers teleported, starting round."
    wait(3)
    m:Destroy()
    local chosen1 = game.Lighting.Chosen1:clone()
    chosen1.Parent = Players[Chosen1].Backpack
    local chosen2 = game.Lighting.Chosen2:clone()
    chosen2.Parent = Players[Chosen2].Backpack
    Players[Chosen1].Character.Humanoid.WalkSpeed = 0
    Players[Chosen2].Character.Humanoid.WalkSpeed = 0
    for i = 3, 0, -1 do
        m.Text = "Round starting in: " ..i
        wait(1)
    end
    for i = 30, 0, -1 do
        script.Lobby:Stop()
        script.Battle:Play()
        Players[Chosen1].Character.Humanoid.WalkSpeed = 16
        Players[Chosen2].Character.Humanoid.WalkSpeed = 16
        h = Instance.new("Hint",workspace)
        h.Text = "New round in: " ..i
        wait(1)
        if Players[Chosen1].Character.Humanoid.Health == 0 then
            h:Destroy()
            m = Instance.new("Message",workspace)
            m.Text = Players[Chosen2].Name.." won!"
            wait(3)
            m:Destroy()
            Players[Chosen2].Character:MoveTo(Vector3.new(-59.5, 1.79, -3))
            script.Battle:Stop()
        end
        if Players[Chosen2].Character.Humanoid.Health == 0 then
            h:Destroy()
            m = Instance.new("Message",workspace)
            m.Text = Players[Chosen1].Name.." won!"
            wait(3)
            m:Destroy()
            Players[Chosen1].Character:MoveTo(Vector3.new(-59.5, 1.79, -3))
            script.Battle:Stop()
        end
    end
end

ChooseDuelers()

Whenever a player dies, the game continues to play. What did I do wrong?

Checking if player died is located on line "39-47" and "48-56"

0
remember next time u post a question tell what is the problem. beastboykafan -5 — 4y

1 answer

Log in to vote
0
Answered by 10 years ago

Use the died event. I think this should work. this is lines 39-56 (Inclusive)

Players[Chosen1].Character.Died:connect(function()
            h:Destroy()
            m = Instance.new("Message",workspace)
            m.Text = Players[Chosen2].Name.." won!"
            wait(3)
            m:Destroy()
            Players[Chosen2].Character:MoveTo(Vector3.new(-59.5, 1.79, -3))
            script.Battle:Stop()
        end)
        Players[Chosen2].Character.Died:connect(function()
            h:Destroy()
            m = Instance.new("Message",workspace)
            m.Text = Players[Chosen1].Name.." won!"
            wait(3)
            m:Destroy()
            Players[Chosen1].Character:MoveTo(Vector3.new(-59.5, 1.79, -3))
            script.Battle:Stop()
        end)
0
Thanks, I was trying to figure out how to use it after I saw it as tip of the day. Relatch 550 — 10y
0
Error: 18:22:54.568 - Died is not a valid member of Model 18:22:54.569 - Script 'Workspace.Main', Line 38 18:22:54.570 - Stack End Relatch 550 — 10y
0
Sorry, "Character.Humanoid.Died:connect"Didn't notice that till now fahmisack123 385 — 10y
Ad

Answer this question