Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can someone help me with my damage and message button?

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)

3 comments

0

Line 7 is one line not sure why it put it on two lines when I copied the code

0

I also wanted to note the message works but just doesn't display the name of the player that clicked it.

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

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.