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

How do I make my function execute?

I'm quite new to using the Chatted method, I still don't fully understand on how to use it. The function will not execute. It doesn't output any errors either.

admins={"iKxtiee","jtefurd","Player","Player1"}
function onChatted(msg)
	if msg == ":regenblocks" then
		game.Workspace.Blocks:Destroy()		
		local blocks=game.Lighting.Blocks:Clone()
		blocks.Parent=game.Workspace
for _,v in pairs(blocks:GetChildren()) do
	for i=1,0,-.01 do
		v.Transparency=i
		wait(.05)
	end
end		
		print("Blocks have regenerated! :)")
	end
end
game.Players.admins.Chatted:connect(onChatted

1 comment

0

Why mark this as a bad post? He didn't break any rules!

2 answers

First off all the script isn't finished. The last line is:

game.Players.admins.Chatted:connect(onChatted --Opened parentheses! Not good!

game.Players.admins.Chatted:connect(onChatted) --Looks better.

Next, game.Players.Admin doesn't exist.

print(#game.Players.Admin:GetChildren()) --doesn't print 4, which is how many people are admins.

The chatted event only runs in the player. We used player added to do that.

game.Players.PlayerAdded:connect(function(player)
end)

We also used pairs to see if the player's name is mentioned on the array on line 1.

for _,array in pairs(table) do
end

This is it finished.

admins={"iKxtiee","jtefurd","Player","Player1", "LordDragonZord"}
game.Players.PlayerAdded:connect(function(plyr)--When a player joins
	plyr.Chatted:connect(function(msg) --If that player talks:
 	   if msg == ":regenblocks" then --and says this:
	for _,adminplayers in pairs(admins) do --If their name is on the array on line 1.
		if plyr.Name == adminplayers then
		game.Workspace.Blocks:Destroy()     --Do this.
	        local blocks=game.Lighting.Blocks:Clone()
 	       blocks.Parent=game.Workspace
	for _,v in pairs(blocks:GetChildren()) do
 	   for i=1,0,-.01 do
 	       v.Transparency=i
 	       wait(.05)
	    end
	end     
		end
	end
 	       print("Blocks have regenerated! :)") --Print.
 	   end
	end)
end)

You used "game.Players.admins" but there won't always be an admin in game, it doesn't work that way. Also you didn't add an extra parentheses in your connection. Try this.

Edit: This is the fixed version.

admins={"iKxtiee","jtefurd","Player","Player1"}

game.Players.PlayerAdded:connect(function(Player) --Fixed
Player.Chatted:connect(function(msg)
for i,n inpairs(admins) do --Have to iterate over admins to check if its the player
if Player.name = n and msg == ":regenblocks" then --If their name is in the admin table and they say regebblocks then
        game.Workspace.Blocks:Destroy()     
        local blocks=game.Lighting.Blocks:Clone()
        blocks.Parent=game.Workspace
for _,v in pairs(blocks:GetChildren()) do
    for i=1,0,-.01 do
        v.Transparency=i
        wait(.05)
    end
end     
        print("Blocks have regenerated! :)")
    end)
end)

5 comments

0

I found a few syntax errors, but corrected them. Anyhow there are no errors in the output, yet the function still isn't executing. Thanks for help though.

0

The players service does not have a Chatted event.

0

Oh, I didn't see that either.

0

Oh, sorry. Let me fix that.

0

Is it good now? Please upvote.

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