edit: where are all the comments and answers why do i have only one dude who has commented and answered this
local debounce = false script.Parent.Touched:Connect(function(otherPart) local player = game:GetService("Players"):GetPlayerFromCharacter(otherPart.Parent) if player and not debounce then debounce = true game:GetService("ReplicatedStorage").TouchEvent:FireClient(player, script.Parent) script.Parent.TouchEnded:Wait() wait(1) debounce = false end end)
hold up
what's that I see?
huhr?
i can't read it
lets zoom in
ok let's be serious now
You'd think, "ey this'll work perfectly"
Well, until you pay attention to this:
Soo...
What's the best way to get when the player actually stops touching the part?
EDIT: I figured it out, you just have to use :GetTouchingParts() and check if the parents of any of the given values are the player's Character. I will keep this question hanging around so that others can see.
local debounce = true script.Parent.Touched:Connect(function(otherPart) local player = game:GetService("Players"):GetPlayerFromCharacter(otherPart.Parent) if player and debounce then debounce = false game:GetService("ReplicatedStorage").TouchEvent:FireClient(player, script.Parent) local function waitUntilNoMoreCollision() -- importent while true do local s = false -- importent for i,v in pairs(script.Parent:GetTouchingParts()) do -- importent if v.Parent == player.Character then -- importent s = true -- importent end end if not s then -- importent print("Player stopped touching!") return -- importent end wait() -- ultra importent end end waitUntilNoMoreCollision() -- importent debounce = true end end)
I would just do it like this which works perfect everytime.
Code:
script.Parent.TouchEnded:Connect(function(hit) if (hit.Parent:IsA("Model")) and (hit.Parent:FindFirstChild("Humanoid")) then -- Code end end)
This basically checks if the parent of the part it hits is a model, and checks if it's a character by finding the humanoid.
local debounce = true script.Parent.Touched:Connect(function(otherPart) local player = game:GetService("Players"):GetPlayerFromCharacter(otherPart.Parent) if player and debounce then debounce = false game:GetService("ReplicatedStorage").TouchEvent:FireClient(player, script.Parent) local function waitUntilNoMoreCollision() -- importent while true do local s = false -- importent for i,v in pairs(script.Parent:GetTouchingParts()) do -- importent if v.Parent == player.Character then -- importent s = true -- importent end end if not s then -- importent print("Player stopped touching!") return -- importent end wait() -- ultra importent end end waitUntilNoMoreCollision() -- importent debounce = true end end)
yey i am smort and i figured it out mahself