What is my goal?
I’m starting to create maps for my game, and I want the player weigh down on these jets when they run around on them. In order to do this, I just want to tween the ship down by a stud if a player is on top of it, and return it back up when they hop off. I also want this system to be efficient because there will likely be multiple instances of the jet in my maps.
The Issue
The problem right now is that the touched events trigger every time a different limb of the player goes inside of the hitboxes or leaves them, plus I’m pretty sure they are retriggering for every instance of the hitbox.
In the output I’m printing the instance that triggers the touched events.
at the end of the video, it actually starts acting as I want it to. I guess because its only the legs entering a single box at nearly the same time.
The pink blocks are some hitboxes I constructed which my script iterates and inserts the touched script inside of.
My Code
My script is placed inside a folder also containing all of the hitbox parts.
--[[ Services ]]
local TweenService = game:GetService("TweenService")
--[[ Constants ]]
local detectoBoxes = script.Parent:GetChildren() -- grabs all the hitboxes
local ship = script.Parent.Parent -- model
local primaryPart = ship.primarypart
--[[ Main ]]
local anchorPos = primaryPart.Position
local goalPosDown = anchorPos + Vector3.new(0, -1, 0)
local goalPosUp = anchorPos + Vector3.new(0, 1, 0)
local tweenInfo = TweenInfo.new(
1,
Enum.EasingStyle.Quint,
Enum.EasingDirection.Out,
0,
false,
0
)
local shipTweenDown = TweenService:Create(primaryPart, tweenInfo, {Position = goalPosDown})
local shipTweenUp = TweenService:Create(primaryPart, tweenInfo, {Position = goalPosUp})
local done = false
for it,ver in next, detectoBoxes do
if ver:IsA("BasePart") then
ver.Touched:Connect(function(hit) print(hit)
if done == false then
shipTweenDown:Play()
done = true
end
end)
ver.TouchEnded:Connect(function()
shipTweenUp:Play()
done = false
end)
end
end
What have I tried?
I know Modules like ZonePlus exist but I’m worried that because I will be making multiple detection boxes as well, I will come across similar issues when it comes to the player moving from one hitbox to another separate hitbox, possibly re-firing the function.
I also know its possible that I could mess around with having a collision group only for a single part of the player, and then for all of the hitboxes for the ship, but I still would likely come across the re-firing issue.
Any advice would be a huge help, thanks!!!