this is bad because if the script is longer it can disconnect it and then everything after or before will stop
can you understand what I mean or should I explain deeper?
Can you explain deeper please, I don’t really understand what you want.
Just put this code in the PlayerAdded
event
connection = base.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
print(hit.Parent.Name.." Has hit the base plate!")
connection:Disconnect()
end
end)
I’m not understanding what you want, can you explain in simpler terms or as steps for what is needed?
I made an example script for this, It will only run once for every player that’s close to the part.
local base = game.Workspace:WaitForChild("Baseplate")
local connection
connection = base.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
print(hit.Parent.Name.." Has hit the base plate!")
---untill it does disconnect it will find more player this means " Has hit the base plate " will print more than once
---TweenService etc...
connection:Disconnect()
end
end)
Just add an extra check too
local base = game.Workspace:WaitForChild("Baseplate")
local connection
local touched = false
connection = base.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and not touched then
touched = true
print(hit.Parent.Name.." Has hit the base plate!")
---untill it does disconnect it will find more player this means " Has hit the base plate " will print more than once
---TweenService etc...
connection:Disconnect()
end
end)
That’s not what will happen, it’ll disconnect almost immediately in most cases, depending if there going to be waits in your code, but if you want to be extra secure, do what @XdJackyboiiXd21 suggested by adding a debounce as well
Have you even tried this script I first mentioned, it should work for every individual player
(Ignore the AmountOfTimesTouched
variable I’ll fix it later)
local Players = game:GetService('Players')
local base = game.Workspace.Baseplate
Players.PlayerAdded:Connect(function(player)
local AmountOfTimesTouched = 0
local char = player.Character or player.CharacterAdded:Wait()
local touched = false
base.Touched:Connect(function(hit)
if hit.Parent == char and touched == false then
touched = true
AmountOfTimesTouched += 1
print(player.Name.."'s times that he/she hit the part: "..tostring(AmountOfTimesTouched))
end
end)
end)
I think they want other players to be able to run this as well. For example, if a player touches the part, the event will fire, and if they touch it again, they won’t be able to fire it.
Ofcourse it will not immediately disconnect if a tween or other functions are before the disconnect. Also a debounce woudnt help here - it will help but still buggy.
Why won’t it. It’s not really a debounce, just an extra check that stops the function from running a second time.
I want detect the player not check the magnitude of it.
ah I forgot that sorry let me check
It checks if the player’s character is close to a part by using magnitude, it’s better than using .Touched
, also it will only run once per player.