Why doesn't this ClickDetector function not work?

The PointLight is the only thing working and nothing else is working. I don’t know why, I don’t think any Syntax errors in my code? I’m stumped.

I’ve tried just making it a CFrame to move it in and out of the way. I’ve also tried just making it’s CanCollide and CanTouch false. But none of those seem to work, why’s that? Here’s my CFrame code.

local ClickDetector = script.Parent.ClickDetector
local On = game.Workspace.On
local Off = game.Workspace.Off

ClickDetector.MouseClick:Connect(function()
	game.Workspace.LightPart.PointLight.Enabled = true
	game.Workspace.HitBox2.CanCollide = true
	game.Workspace.HitBox2.CanTouch = true
	game.Workspace.HitBox.CanCollide = false
	game.Workspace.HitBox.CanTouch = false
	for count = 1, 1 do
		wait (0.001)
		On.CFrame=CFrame.new(On.Position+Vector3.new(1,1,1))
		Off.CFrame=CFrame.new(Off.Position+Vector3.new(-1,-1,-1))
	end
end)

Play the game, use ClickDetector and then check output for any potential errors/warnings related to this script.

“HitBox2 is not a valid member of Workspace “Workspace””

Is your script local script or server script?

Server sided script. I need to extend this so I get

Use WaitForChild() then.

local hitBox2= game.Workspace:WaitForChild("HitBox2")
local hitBox= game.Workspace:WaitForChild("HitBox")

Or the path to the part is wrong.

Check object hierarchy before and while playing the game.

So do I change, “game.Workspace.HitBox” to just “HitBox” etc etc.

wsadwas
It’s the same in game as this.

Yeah, basically the error is that it can’t find the object in the workspace. So either your path to it is wrong (it’s not directly in the workspace but rather in another object in the workspace) or you are trying to access it before it’s created

Rather use script.Parent then.

Thanks, now all I need to do is make the part go visible. and the other one to appear! And also the other hitbox to turn on…

When I put these 2 lines in,

game.Workspace.Off.Transparency = 0
	game.Workspace.On.Transparency = 1 

It doesn’t work.

Could you please send a picture of your explorer tab then.

explorer

Thanks, try this then: I’m assuming this is the script in HitBox2

local ClickDetector = script.Parent.ClickDetector
local On = game.Workspace:WaitForChild("On")
local Off = game.Workspace:WaitForChild("Off")
local lightPart =  game.Workspace:WaitForChild("LightPart")
local otherHitBox = game.Workspace:WaitForChild("HitBox")

ClickDetector.MouseClick:Connect(function()
	lightPart.PointLight.Enabled = true
	script.Parent.CanCollide = true
	script.Parent.CanTouch = true
	otherHitBox .CanCollide = false
	otherHitBox .CanTouch = false
    On.Transparency = 1 
    Off.Transparency = 0
	for count = 1, 1 do
		wait (0.001)
		On.CFrame=CFrame.new(On.Position+Vector3.new(1,1,1))
		Off.CFrame=CFrame.new(Off.Position+Vector3.new(-1,-1,-1))
	end
end)

So close! Tysm, but the Off Button and hitbox for some reason just isn’t appearing… Very annoying, I’m asking lots from you, but thank you greatly.

1 Like

Perhaps the hitbox isn’t anchored so it falls into the void and gets destroyed.

Yes! Thank you. All I have to do is fix some CFrame issues with it actually landing in the right place and then one more issue and then it is done. Thank you so much.