Having Problems with making Door System

Hi Developers!

So i am trying to make system when player clicks on button wich is in workspace.Clickboards.(Making system wich allows to every board).Textbutton.Activated:Connect(Function)

This is my code

local deb = false

local function Deletingdoor(door)
	if deb ~= true then
		deb = true
		workspace.Clickboards:WaitForChild(door).Clicks.Value = workspace.Clickboards:WaitForChild(door).Clicks.Value + 1
		deb = false
	end
end

for i,v in pairs(workspace.Clickboards:GetChildren()) do
	v.SurfaceGui.TextButton.Activated:Connect(Deletingdoor(v.Name))
end

output is attempt to call a nil value

Edit:Wanna make it client sided so when player clicks it only do it for him not for server and script is in startergui

Thank you!

1 Like

Your current code gives the return value of Deletingdoor (which is nil) to the activated event’s connect method. You can fix this problem by giving it a function that calls Deletingdoor. This adds some extra function creation but I can’t figure out a way to do it without that.

local deb = false

local function Deletingdoor(door)
	if deb ~= true then
		deb = true
		workspace.Clickboards:WaitForChild(door).Clicks.Value = workspace.Clickboards:WaitForChild(door).Clicks.Value + 1
		deb = false
	end
end

for i,v in pairs(workspace.Clickboards:GetChildren()) do
	v.SurfaceGui.TextButton.Activated:Connect(function()
		DeletingDoor(v.Name)
	end)
end

Here are a couple of things that are not related to your problem, but maybe worth mentioning:
The variable deb seems quite useless. It’s set back to false instantly after changing the door’s Clicks value, which means it’s probably always false when Deletingdoor is called. It could be true if some of the doors didn’t exist when Deletingdoor was called with its name and the function was called with an existing door’s name after that, but I don’t think that would happen and I believe you don’t expect it to happen either. You could also use the += operator to shorten the line where you update the Clicks value.

1 Like