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

Why is this not working??

I couldn't find an output error with this script, but for some reason it won't work...

debounce = true
done = {}
script.Parent.Touched:connect(function(player)
	if debounce == true then
		debounce = false
		a == false
		for i,v in pairs (done) do
			if player.Parent.Name == done[i] then
				open() --I hid the function, but it's correct
				a = true
			end
		end
		if a == false then
			ls = game.Players:FindFirstChild(player.Parent.Name).leaderstats.Admins
			ls.Value = ls.Value-1
			done.insert[player.Parent.Name]
			open()
		end
		a = false
		wait(1)
		debounce = true
	end
end)

What should happen is this: When a player touches the brick, he should only be charged once instead of all the time when he touches the brick. But it doesn't work properly and I can't find an output error (not sure why)...

2 comments

0

Do you have anything for your script to do if a is true?

0

On line 6, you have two equal signs. Is there supposed to be an if statement? If not, remove one. We need a better explanation of this script, especially pertaining the 'a' variable.

1 answer

✓ Accepted answer

If we run this script, we get the following error:

input:6: syntax error near '=='

(Sometimes syntax errors aren't visible when you run in Solo or as a Server, so just pressing Play to play in normal studio sometimes helps catch them)

On line six you have written:

-- (Incorrect snippet for explanatory use)
a == false

This probably is either meant to be a condition that you forgot to write (like if a == false then) or an assignment a = false.

Based on the context, it's almost surely meant to be the assignment a = false.


Once we fix that, we have a second syntax error:

input:17: syntax error near 'open'

This is caused by the previous line:

-- (Incorrect snippet for explanatory use)
done.insert[player.Parent.Name]

Since insert is a function, we would use parenthesis (( )) not square brackets ([ ]):

-- (Incorrect snippet for explanatory use)
done.insert(player.Parent.Name)

However, unlike other languages, Lua doesn't have a insert by default in tables. This is because of how Lua indexes things and the mess that would create. You must use the function table.insert:

table.insert(done, player.Parent.Name);

Please also be warned that in some cases, the Parent of an object hitting will be nil. This would cause errors in your script. You should add a check to make sure player.Parent is not nil.


I would also use a better name than player for the object touching.


Also note that there is a function of the Players service:

game.Players:GetPlayerFromCharacter(player.Parent)

which you could use instead of

game.Players:FindFirstChild(player.Parent.Name)

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