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

Can someone help me with my damage and message button?

Asked by 3 years ago

I am trying to print a message that a player clicked the button then do 500 damage to all players. Please explain and help me figure out why this isn't working.

local M = Instance.new("Message", game.Workspace)
local p = game.Players:GetChildren()


function onClicked()

    M.Text = "The button was clicked by .. " .. game.Players.LocalPlayer.Character.Name
    wait(2)
    M:remove()

    for i = 1, #p do
        p[i].Character.Humanoid:TakeDamage(500)
    end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)
0
Line 7 is one line not sure why it put it on two lines when I copied the code Tipsy_Juicebox 12 — 3y
0
I also wanted to note the message works but just doesn't display the name of the player that clicked it. Tipsy_Juicebox 12 — 3y
0
That's okay, it gets wrapped to the next line, on the left it says line 7 and the second part is in line 7 as well showing that it's on the same line. Message is deprecated, so is remove. Check the output for errors greatneil80 2647 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

I figured it out. Here is the updated working code.

function onClicked(player)
    local p = game.Players:GetPlayers()
    local M = Instance.new("Message", game.Workspace)

    wait(0.5)

    M.Text = "The button was clicked by .. " .. player.Name
    wait(2)
    M:remove()

    for i = 1, #p do
        if p[i] then
        p[i].Character:WaitForChild('Humanoid'):TakeDamage(500)
        end
    end
end
print("Kill button script ended")
script.Parent.ClickDetector.MouseClick:connect(onClicked)
Ad

Answer this question