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

playerpoint rain on command help?

local isAdmin = {[""] = true, [""] = true, [""] = true}
 
function onChatted(message, player)
    if message == "pprainplz" and isAdmin[player.Name] then
        game.Workspace.PPRain.Disabled = false
game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(message) onChatted(message, player) end)
end)

Ive tried to do this but it wont work when i say pprainplz to make it rain the parts from the other script, and i know the other works because i've tried it

2 comments

0

Please put in code block.

0

sorry, its in code block now.

1 answer

✓ Accepted answer

The PlayerAdded event in this code will never run because it is inside the onChatted function which is never called. You are also missing multiple end's in your code.

local isAdmin = {[""] = true, [""] = true, [""] = true}

function onChatted(message, player)
	if message == "pprainplz" and isAdmin[player.Name] then
		game.Workspace.PPRain.Disabled = false
	end
end

game.Players.PlayerAdded:connect(function(player)
	player.Chatted:connect(function(message) 
		onChatted(message, player)
	end)
end)

To further improve this code you can use a function to check if the player is in the table. So you do not have to set each player to true. This function is also not case sensitive.

I also only call the onChatted function if the player is considered an admin. This allows for less code repetition if you wish to make multiple admin commands.

local isAdmin = {"Bob", "Joe"}

function inAdminTable(Name)
	for _,n in pairs(isAdmin) do
		if n:lower() == Name:lower() then
			return true
		end
	end
end

function onChatted(message, player)
	if message == "pprainplz"  then
		game.Workspace.PPRain.Disabled = false
	end
end

game.Players.PlayerAdded:connect(function(player)
	if inAdminTable(player.Name) then
		player.Chatted:connect(function(message) 
			onChatted(message:lower(), player)
		end)
	end
end)

1 comment

0

Thank you so much!

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