If Statement running, despite there being Children inside of an Object? [SOLVED]

  • Each tool has the same number, and if you have the correct number, I want it to proceed.

  • The creating of the children are though a LocalScript, whereas the Script in the topic is in Workspace

If you have anymore questions, just ask.

I don’t know what you mean by this
what’s the point of checking the tool’s number if they’re all the same?
what do you mean by “have the correct number”? what is having a number in this context?
what do the children have to do with this?

1 Like
  1. If you don’t have the right number, which is a NumberValue inside the tool, then it shouldn’t work. The script doesn’t check the tool itself, it checks for the right number inside of it.

  2. The player must have the right tool, to be able to have the correct corresponding number in it. Otherwise, the player shouldn’t be able to edit the whiteboard.

  3. All the numbers are the same, but not every player is given a tool, only certain ranks get given one. If the player meets all these requirements, they can add children or paint to the whiteboard, etc.

Currently, it is always turning white now regardless. However, it should turn black, when there are no children, but it doesn’t for some reason. Even though the RemoteEvent is fired;

LocalScript:

--Variables
local RemoteEvent = script.Parent.RemoteEvent
local BoardScreen = script.Parent.SurfaceGui.Frame -- Screen of the board
local OFF = Color3.fromRGB(47, 47, 47)

function CopyEnabledTrue()
	if #BoardScreen.Container:GetChildren() == 0 then
		BoardScreen.BackgroundColor3 = OFF --turns black if statement runs
	end
end

RemoteEvent.OnClientEvent:Connect(CopyEnabledTrue)

Script:

--Variables
local perms = false 
local debounce = false
		
local Whiteboard = script.Parent 
local BoardScreen = Whiteboard.SurfaceGui.Frame 
local ScreenLabel = BoardScreen.ScreenLabel 
		
Whiteboard.Touched:Connect(function(marker)
	if marker ~= nil and marker.Parent ~= nil and marker.Parent:FindFirstChild("CardNumber") ~= nil and marker.Parent.CardNumber.Value == 55 then
		if not debounce then
			debounce = true
			if perms then
				copy.Enabled = false
				copy.ImageButton.LocalScript.Disabled = false
				task.wait(1)
				local RemoteEvent = script.Parent.RemoteEvent
				RemoteEvent:FireAllClients() --Do I put something in here, and should this be in .Touch or .TouchEnded?
			else
				copy.Enabled = true
				copy.ImageButton.LocalScript.Disabled = false
			end
		end
		debounce = false
	end
end)
		
local ON = Color3.fromRGB(255, 255, 255)
local OFF = Color3.fromRGB(47, 47, 47)
		
Whiteboard.TouchEnded:Connect(function()
	if copy.Enabled == false then
		task.wait(1)
		perms = false
	elseif copy.Enabled == true then
		BoardScreen.BackgroundColor3 = ON
		ScreenLabel.TextTransparency = 0
		task.wait(2)
		ScreenLabel.TextTransparency = 1
		perms = true
	end
end)
  1. Does it matter, if the RemoteEvent is fired, in .Touch or .TouchEnded or not?
  2. Are there any problems, with the scripts?
  3. Do I have to put something inside of the :FireAllClients() brackets?

Edit: Is there an easier way of doing this since it does not work. Using a BoolValue, toggled when a child is created through the LocalScript, which creates them maybe? Or something else?

Did you check the children from the server? Since this is a touched event it must run on the server meaning any client changes will not have any effects.

1 Like

Yes, but since the ImageLabels were being created in a LocalScript they couldn’t see them and so I had changed them to a LocalScript.

As you said, it is quite hard since .Touch only works in a Script when you detect when the part is touched, but the checking of the ImageLabels can only be done on the client in this case.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.