As the title says, whenever a part that isn’t a Player touches my script, it completely breaks it and stops it from running. The script itself throws no errors in the console, it just stops running, and I have no idea why. I’d prefer to use the Players:FindFirstChild() method as a last-case scenario as I want my script to work in as many cases as possible. Here is my script:
TouchPart.Touched:Connect(function(Hit)
print("Touched!")
if Debounce == false then
Debounce = true
local Character = Hit.Parent
local Player = Players:GetPlayerFromCharacter(Character)
if Player then
print("Is Player!")
if GlobalDebounces == true then
GiveItem(Player)
task.wait(DebounceTime)
Debounce = false
else
local Player = Players:GetPlayerFromCharacter(Character)
local UserID = Player.UserId
wait(0.01)
if table.find(DebounceUsers, UserID) == nil then
table.insert(DebounceUsers, UserID)
GiveItem(Player)
task.wait(0.05)
Debounce = false
task.wait(DebounceTime - 0.05)
table.remove(DebounceUsers, table.find(DebounceUsers, UserID))
else
task.wait(0.05)
Debounce = false
end
end
end
end
end)
PS: The Code is printing “Touched!” but not “Is Player!” so it must be breaking when it calls GetPlayerFromCharacter, but I have no idea how I’d do this without using that method, besides the method I stated up above.