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

Script works in a brick, but not in a Gui. Why?

I made a script that explodes everyone in a server one at a time, and I had it fire each time you clicked a brick, and it worked when it was in the brick. I thought such a thing would be more fit for a Gui, so I put it in a Gui, changed MouseClick to MouseButton1Clickand then realized it doesn't work. I don't know why D; It puts players in the table just fine but the function just isn't firing. ;c

local Players = {}

game.Players.PlayerAdded:connect(function(Player)
	table.insert(Players,Player)
	print(Players,Player)
end)

game.Players.PlayerRemoving:connect(function(Player)
	table.remove(Players,Player)
end)

function GenocideBomb()
	for i, v in pairs (Players) do
		local Explode = Instance.new("Explosion")
		Explode.BlastRadius = 5
		Explode.BlastPressure = 500000
		Explode.Position = v.Character.Torso.Position
		Explode.Parent = v.Character
		wait(1)
	end
end


script.Parent.MouseButton1Click:connect(function()
	print("Fired")
	GenocideBomb() 
end) -- https://www.youtube.com/watch?v=4ZCZ1pl37Ag

Oh, also when a player leaves the script doesn't remove the player from the table and says number expected got object-- so itwouldbeniceifyouhelpedmewiththattoo. How would I fix this problem and avoid it in the future?

1 answer

function RemoveFromTable(thetable, toberemoved)
    if thetable == nil then
        error("ERROR | FIRST ARGUMENT/TABLE IS NIL | FUNCTION: RemoveFromTable")
    end
    local istoberemovedintable = false
    for _, yesorno in pairs(thetable) do
        if yesorno == toberemoved then
            istoberemovedintable = true
        end
    end
    if istoberemovedintable == false then
        error("ERROR | SECOND ARGUMENT/OBJECT IS NOT IN TABLE | FUNCTION: RemoveFromTable")
    end
    for i = 1/table.getn(thetable), table.getn(thetable) do
        if thetable[i*table.getn(thetable)] == toberemoved then
            table.remove(thetable, i*table.getn(thetable))
        end
    end
end

table.remove() requires two things: a table and the spot of the variable or whatever that's supposed to be remove. And for your actual question: Please send more detail like your explorer or whether FilteringEnabled is turned on or not.

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