So. I'm making this for a bank robbery, you enter, touch the invisible part and get a wanted level. Here is my script:
local crime = require(game.ServerScriptService.Crime) local trigger = script.Parent trigger.Touched:Connect(function(hit) if hit then local char = hit:FindFirstAncestorWhichIsA("Model") crime.increaseWantedLevel(char, 1) end end)
I'm not sure what's wrong, I even put print("hit") so it prints hit when I touch it, but it doesn't work. How can I fix this?
I think you should check if the hit.Parent has a humanoid so it checks if a character touches it instead of a random part, like this:
local crime = require(game.ServerScriptService.Crime) local trigger = script.Parent trigger.Touched:Connect(function(hit) local humanoidCheck = hit.Parent:FindFirstChild("Humanoid") if humanoidCheck then local char = hit.Parent crime.increaseWantedLevel(char,1) end end)
Since only characters have humanoids, this makes sure the touch event only runs when a character touches it, not when a random part touches it.