hey all,
I have this reload/refuel part for my planes. If the vehicle touches it, the player must wait two seconds while touching the part with their engine off for the reload/refueling process to begin. While the touch is true, the guns are immediately fully loaded, and the fuel and health replenishment begins in increments.
Problem is, is that this does not stop even if the vehicle stops touching the part.
Anyone know how to solve this?
edit: ok so re-iteration a little, but it is still a little raw. I don’t know if the code will be able to handle multiple objects at once
local supplyteam = "Blue"
local touching
local tag
function status(Object, tag)
if Object and tag == "here" then
touching = true
end
if Object and tag == "gone" then
touching = false
end
end
script.Parent.Touched:Connect(function(Object)
tag = "here"
status(Object, tag)
if Object:IsA("BasePart") then
local seatfind = Object.Parent.Parent:FindFirstChild("PlaneSeat")
if seatfind ~= nil then
local planeteam = Object.Parent.Parent:FindFirstChild("Team")
local values = Object.Parent.Parent:FindFirstChild("Values")
local Hp = Object.Parent.Parent.Hp
if planeteam.Value == supplyteam then
if values.Active.Value == false then
while touching == true do
wait(2)
values.Ammo.Bullets.Value = values.Ammo.Bullets.MaxBullets.Value
values.Ammo.Bombs.Value = values.Ammo.Bombs.MaxBombs.Value
values.Ammo.Missiles.Value = values.Ammo.Missiles.MaxMissiles.Value
if values.Fuel.Value >= 93 and values.Fuel.Value <= 99 or values.Fuel.Value == 100 then
values.Fuel.Value = 100
else
values.Fuel.Value = values.Fuel.Value + 8
end
if Hp.Value >= Hp.Maxhp.Value - 59 and Hp.Value <= Hp.Maxhp.Value - 1 or Hp.Value == Hp.Maxhp.Value then
Hp.Value = Hp.Maxhp.Value
else
Hp.Value = Hp.Value + 60
end
if values.Turret then
local children = values.Turret:GetChildren()
for i = 1,#children do
if children[i].Name == "GunTurret" then
if children.FiringGun.Value == false then
i.Bullets.Value = i.Bullets.MaxBullets.Value
end
end
end
end
end
end
end
end
end
end)
script.Parent.TouchEnded:connect(function(Object)
tag = "gone"
status(Object, tag)
end)
Thanks!