Iam creating a game like Power Simulator, so i started create the training areas, i want check when player enter on area and when player leave, i tried used Touch and TouchEnded(the area is a Part), but every times touch and touchended active together, iam 2 days traying fix that, anyone can helpme ?
Code:
--Variables
local Part = script.Parent
local module = require(game.Workspace:WaitForChild("ModuleScript"))
local debounce = false
script.Parent.Touched:Connect(function(hit)
if not module.Get then
if hit.Parent:FindFirstChild("Humanoid") and debounce== false then
debounce = true
print(hit.Parent.Name)
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
print(player.Name)
module.Training(player,50,Part,"Endurance",true)
wait(1)
debounce = false
end
end
end)
script.Parent.TouchEnded:Connect(function(hit)
if module.Get then
if hit.Parent:FindFirstChild("Humanoid") and debounce== false then
debounce = true
print(hit.Parent.Name.."Leaved")
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
print(player.Name)
module.Training(player,50,Part,"Endurance",true)
wait(1)
debounce = false
end
end
end)
The part is here
“ignore the green one, and CanCollide is false, so player can enter”
This is my module
local touching = false
local StartTraining = game.Workspace:WaitForChild("StartTraining")
local StopTraining = game.Workspace:WaitForChild("StopTraining")
local module = {}
function module.Get()
return touching
end
function module.Training(player,amount,Part,Stat,Touchings)
touching = Touchings
if touching then
StartTraining:Fire(player,amount,Part,Stat)
else
end
end