-
What do you want to achieve? I Want to fix an issue with my Click Detector
-
What is the issue? Though This Click Detector is printed in the output and recognized it is not firing the MouseClick Event when clicked.
-
What solutions have you tried so far? I have tried increasing the max distance, checked that there is no higher elevated mouse click event active, and checked if the Cursor icon changed.
Yes I have checked all of the other topics that have the same issue as me but they all had different circumstances that did not apply to my issue. The posts solutions were things I had already checked before making this topic. Though I don’t doubt I missed something obvious and that’s why I’m here.
Here is my function that is not returning errors but is stopping at the MouseClick Event
print("RoomChanged")
local Selection = Rep.Segments:GetChildren()
local NextRoom = Selection[math.random(1, #Selection)]
for _, Item in pairs(CurentRoom.Value:GetChildren()) do -- CurrentRoom.Value is a Model
print("ForLoop",Item.Name)
if Item.Name:match("Exit") then
Item:FindFirstChildOfClass("ClickDetector").MouseClick:Connect(function(player)
print("MouseClick")
Selection = Rep.Segments:GetChildren() -- After saving the variables change the chosenRoom
NextRoom = Selection[math.random(1, #Selection)] -- Choose a random model from all of the models in ReplicatedStorage.Segments folder
local clone = NextRoom:Clone()
clone:PivotTo(CurentRoom.Value.PrimaryPart.CFrame + CFrame.new(0,0,(clone.PrimaryPart.Size.Z * 2) + 15).Position)
clone.Parent = game.Workspace
player.Character.HumanoidRootPart.CFrame = NextRoom.PlayerSpawn.CFrame
RoomNum.Value += 1
CurentRoom.Value = NextRoom
end)
end
end
end)```
Everything in this function fires up until The Click Detector Event is fired Where the print statment does not print meaning it stopped. The print statements set up end right before the Click Event. So that is where I left off and need any solution I can get.
6 Likes
Not sure what the problem may be. Maybe try restarting studio. Try adding an else for printing.
3 Likes
I have restarted studio but Have not tried transferring over the game assets into a new place and testing if maybe just the place is broken.
2 Likes
the for loop gets every object in the model which is The CurrentRoom.Value. The if statement checks if the parts inside the model contain “Exit” In the name then if it does I know that it has A click Detector inside. this is how I set it up for my use case.
2 Likes
if Item.Name:match("Exit") then
if Item:FindFirstChildOfClass("ClickDetector") then
Item["name of clickdetetor"].MouseClick:Connect(function(player)
--rest of input here--
end)
end
end
Try this and see what happens.
2 Likes
Same result which is no errors and no print statement fires. Also I tried similar stuff like switching the FindFirstChild Out. But always the same
1 Like
Instead of match use find. just check
That does not change anything because I had a print statement there which worked either way(I tired both lol)
you’re sure that the event is connected right?
If not, try putting a print statement after the if statement
1 Like
When I print out all the parts including the Click Detector itself and its parent and everything around it, It prints what I want which is the Click Detector and the Parent of it. So I’m going to try to see if I can access the property’s of the Click Detector without getting an error or not printing anything at all.
Yes it works. Ill post a screenshot in a second of the output
1 Like
For further context a random room is chosen, cloned, then placed ahead of the current room that the player is in. Then the player is moved to the chosen room, the current room variable is set to the new room, so is the unrelated RoomNum Variable. This should repeat every time the player clicks the Click Detector.
oh wait. Is the click detector parented in a Union?
(show me hierarchy if not, its still helpful)
1 Like
I think that it is useful to mention that the Model called Segment is a duplicated model from replicated storage. It is the randomly chosen one.
hmmm
Also, is the cancollide of Exit false? (im just telling you everything I find, idk if it would be the issue but wortha try)
1 Like
No the exit part is fully colidable and touchable. I think were kind of at a stalemate here.
1 Like
ok im reaching “stupid solutions” now:
Try deleting and adding a new click detector
Put a random click detector on the ground and a seperate script for it to see if that works
Oh wait also:
you’re sure that you’re connecting the click detector that is in workspace (the clone) and NOT the one that is in replicated storage right? (maybe change the name of the clone and then check if the parent of Exit is that different name or not)
1 Like
Alright and if all of that fails Ill recreate everything in a new place and test it again.Thanks
1 Like
Holly I think You found it, It was somehow binded to the one in replicated storage even though its grabbing the copy from the workspace. Ill apply this fix and then put the solution. Thanks a lot!
1 Like