This is a tutorial because i couldnt find a actual forum telling you how to do it
local touching = false
script.Parent.Touched:Connect(function(hit) --checks if the player touched
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if player then
touching=true
end
end)
script.Parent.TouchEnded:Connect(function(hit) --checks when the player stopped touching
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if player then
touching=false
end
end)
coroutine.wrap(function()
while touching do -- While touching loop
task.wait()
--Your script here
end
end)()
Hope i helped (this is a repost because i did a mistake in the last post and couldnt delete it)
Actually it makes sure they’re some sort of NPC or a player character. To ensure it’s a player character you must run game.Players:GetPlayerFromCharacter(hit.Parent) and check if it returns a player or nil. If it returns nil but it looks like a character(it has a humanoid, body parts, etc.) it’s probably an in-game NPC.