Hello there. On the second touch of the whiteboard, if there are no children, I want to change the board to black. Howbeit, if there are children on the second touch, I want the colour of the frame to stay white, but I am having some problems with it.
This is where the problem is:
local ON = Color3.fromRGB(255, 255, 255) --white screen
local OFF = Color3.fromRGB(47, 47, 47) --black screen
Whiteboard.TouchEnded:Connect(function()
if copy.Enabled == false then --this only applies if it isn't enabled
if #BoardScreen.Container:GetChildren() == 0 then --if there are no children then it turns off
BoardScreen.BackgroundColor3 = OFF
task.wait(1)
perms = false
elseif #BoardScreen.Container:GetChildren() ~= 0 then --if there are children it stays as white
BoardScreen.BackgroundColor3 = ON
task.wait(1)
perms = false
end
elseif copy.Enabled == true then
BoardScreen.BackgroundColor3 = ON
ScreenLabel.TextTransparency = 0
task.wait(2)
ScreenLabel.TextTransparency = 1
perms = true
end
end)
I have checked the path, and the path seems to be fine, with no errors in the output.
This is the full TouchScript, which has been updated:
local perms = false
local debounce = false
local Whiteboard = script.Parent --part
local BoardScreen = Whiteboard.SurfaceGui.Frame --frame
local ScreenLabel = BoardScreen.ScreenLabel --surfacegui
Whiteboard.Touched:Connect(function(marker)
if marker ~= nil and marker.Parent ~= nil and marker.Parent:FindFirstChild("CardNumber") ~= nil and marker.Parent.CardNumber.Value == 348 then
if not debounce then
debounce = true
if perms then
copy.Enabled = false
copy.ImageButton.LocalScript.Disabled = false
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
if #BoardScreen.Container:GetChildren() == 0 then
BoardScreen.BackgroundColor3 = OFF
task.wait(1)
perms = false
elseif #BoardScreen.Container:GetChildren() ~= 0 then
BoardScreen.BackgroundColor3 = ON
task.wait(1)
perms = false
end
elseif copy.Enabled == true then
BoardScreen.BackgroundColor3 = ON
ScreenLabel.TextTransparency = 0
task.wait(2)
ScreenLabel.TextTransparency = 1
perms = true
end
end)
I have tried changing where I put the if statement, but so far nothing has worked.
These are the questions that I have:
Am I doing something wrong?
Is there a better, alternative script that would work better?
If youâre adding the children clientside (via local script) and listening for childrenadded on the server (via a normal script), then itâs not gonna detect the children added.
You can add the children via server, or add some sorts of event to replicate the children from client to server, but making sure there is sanity checks and protection against exploit.
Which option, do you think might work the best? If not, could I maybe fire from the Server somehow, and have the children checked in a LocalScript. If that is where it would work better maybe? RemoteEvent or Binable?
The problem is, is that I want to use .Touch which will only work in a normal Script, but then I need a LocalScript for the children. That is for it to work.
@aruruy0155, the children are currently inside of a Frame, called (Container).
assuming you want the serverscript to know how many children there are, youâd have something like this
--server script
numChildren = 0
RemoteEvent.OnServerEvent:Connect(function(player, numChildrenByPlayer)
validate player
numChildren = numChildrenByPlayer
end)
-- local script
function tell server how many children there are
Remote:FireServer(numChildren)
end
on child added to frame
tell server how many children there are
on child removed from frame
tell server how many children there are
How would I fire a RemoteEvent from the Server if that is possible, and listen for it in a LocalScript, for the if #BoardScreen.Container:GetChildren() == 0 then, to happen?
--server script
someRemote:FireClient(somePlayer, 2, 4, 8)
--local script
function someFunction(a, b, c)
print(a, b, c) --prints 2, 4, and 8
end
someRemote.OnClientEvent:Connect(someFunction)
they can be anywhere as long as the local script is somewhere local scripts run, the server script is somewhere server scripts run, both scripts can see the remote event, and the local script is setup to reference the new gui if starterGui is recreating the gui whenever you respawn
Says âArgument 1 missing or nilâ, in the Output:
Whiteboard.TouchEnded:Connect(function()
if copy.Enabled == false then
local RemoteEvent = script.Parent.RemoteEvent
RemoteEvent:FireClient() --here is the error
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)
I think I may need to put something in the brackets â()â, but not sure.
you need to specify the player to fire to
I think it would either be all players, so youâd instead of :FireAllClients()
or youâd fire to the player that touched it, so youâd work with the argument given by .TouchEnded to figure out which player it is
if marker ~= nil and marker.Parent ~= nil and marker.Parent:FindFirstChild("CardNumber") ~= nil and marker.Parent.CardNumber.Value == 348 then
Basically, I want it to be anybody who has the right tool and the correct number in the Card, but how would I put that inside the brackets (if I need to)?