I’m working on a game and I have a click detector that i’m using on a model. However, recently, the click detector is not firing any of it’s events, and I have no idea why, as it was working before.
The cursor is still changing to the default click cursor when I hover over it. I added a print statement to the clicked event, and the print statement isn’t even run. I have no idea why this is happening.
Here is a code snippet
script.Parent:WaitForChild('Select').MouseClick:Connect(function(plr)
print('event received')
if plr.Team == script.Parent.Data.Team.Value then
print('selected')
selected.Value = true
game.ReplicatedStorage.AddToSelected:FireClient(plr, script.Parent, true)
script.Parent.SelectionBox.Visible = true
end
end)
Neither prints are run. I also added breakpoints, and the line that connects the function IS being run, but the function itself is never run.
Why is this happening?
“Select” is a click detector that is a part of the model.
Here is a view of the hierarchy.
Everything inside the “unitstuff” folder is cloned to each unit by the server, each unit being a model.
This was working earlier, so I’m not sure what’s happening here.
I’ve also verified that all of the items in here are in fact being cloned over, as they are visible in the hierarchy. No scripts are disabled either.
I would recommend just having the script be a child to the click detector, this would make the script easier because you could have something like this
The thing is, I don’t beleive this makes a difference. It would also require restructuring the variables in the code. Plus, the script isn’t just for the click detector, it also handles several other things related to units such as movement.
The script was recognizing and using the clickdetector completely fine and normally before, and I see no reason as to why it wouldn’t work now.
I apologize, I was just uninformed about what else was in this script
As part of a possible solution, have you made any adjustments to this part of the script recently? If so, were they major and could you perhaps revert the place to a time where it was working?
Does that mark this question as solved already, or are you still having a problem? Just to know.
I figured it might be because the UnitScript would run even before getting cloned to the part, you should make it disabled and only enabled when it actually gets cloned into the part you want the click to work on.
Sorry, I had to go for a moment.
The unitstuff folder is a part of ReplicatedStorage, so it doesn’t run until it’s cloned. However, I’ve encountered a new problem. None of the code inside the UnitScript seems to be running, and functions aren’t being connected.
So it seems this is a problem with the UnitScript not connecting functions properly. It is running, as breakpoints are being hit, but the script just wont run.