I am trying to code for a Tower Defense game, and i have run across a problem with the elevators to send players to the map(Technically I am using submarines, not elevators). I used a touched event to make the player go into the sub when they touch a box I made. The script then check to find the next seat not occupied, and makes the player sit there and also disables movement. Then, in a local script in StarterCharacter, I used the seated event to make a leave button appear. A local script in the button makes you leave the seat, destroy the seat weld, and enable controls again. The problem occurs when I try to get back in. The touched event does not fire at all, as there are no errors and i put a print() in the fired function, which didn't print. I also went to a teleporting door I made, which works perfectly fine, and the touched event would not fire after leaving the sub for the first time. Here are the three scripts: In a server script inside the box parts:
Entry = script.Parent
Sub = script.Parent.Parent.Submarine
debounce = false
Entry.Touched:Connect(function(Hit)
if debounce == false then
debounce = false
local Humanoid = Hit.Parent:FindFirstChildWhichIsA("Humanoid")
if Humanoid then
if Sub.Seat1.Occupant == nil then
Sub.Seat1:Sit(Humanoid)
if Sub.Parent.ReadyingForDeployment.Value == false then
Sub.Parent.ReadyingForDeployment.Value = true
end
elseif Sub.Seat2.Occupant == nil then
Sub.Seat2:Sit(Humanoid)
if Sub.Parent.ReadyingForDeployment.Value == false then
Sub.Parent.ReadyingForDeployment.Value = true
end
elseif Sub.Seat3.Occupant == nil then
Sub.Seat3:Sit(Humanoid)
if Sub.Parent.ReadyingForDeployment.Value == false then
Sub.Parent.ReadyingForDeployment.Value = true
end
elseif Sub.Seat4.Occupant == nil then
Sub.Seat4:Sit(Humanoid)
if Sub.Parent.ReadyingForDeployment.Value == false then
Sub.Parent.ReadyingForDeployment.Value = true
end
elseif Sub.Seat5.Occupant == nil then
Sub.Seat5:Sit(Humanoid)
if Sub.Parent.ReadyingForDeployment.Value == false then
Sub.Parent.ReadyingForDeployment.Value = true
end
elseif Sub.Seat6.Occupant == nil then
Sub.Seat6:Sit(Humanoid)
if Sub.Parent.ReadyingForDeployment.Value == false then
Sub.Parent.ReadyingForDeployment.Value = true
end
elseif Sub.Seat7.Occupant == nil then
Sub.Seat7:Sit(Humanoid)
if Sub.Parent.ReadyingForDeployment.Value == false then
Sub.Parent.ReadyingForDeployment.Value = true
end
elseif Sub.Seat8.Occupant == nil then
Sub.Seat8:Sit(Humanoid)
if Sub.Parent.ReadyingForDeployment.Value == false then
Sub.Parent.ReadyingForDeployment.Value = true
end
end
wait(0.5)
debounce = false
end
end
end)
In a local script inside of StarterCharacter:
Player = game.Players.LocalPlayer
Character = game.Players.LocalPlayer.Character
Humanoid = Character.Humanoid
Humanoid.Seated:Connect(function(active)
if active then
local Controls = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule")):GetControls()
Controls:Disable()
Player.PlayerGui.LeaveSub.Enabled = true
end
end)
In a local script inside of the leave button:
Button = script.Parent
Player = game.Players.LocalPlayer
Humanoid = Player.Character:WaitForChild("Humanoid")
Button.Activated:Connect(function()
local CurrentSub = Humanoid.SeatPart.Parent
local TpReference = CurrentSub.TpRefernce
local Seat = Humanoid.SeatPart
Seat:FindFirstChild("SeatWeld"):Destroy()
Humanoid.Parent.HumanoidRootPart.CFrame = CFrame.new(TpReference.Position)
Button.Parent.Parent.Enabled = false
local Controls = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule")):GetControls()
Controls:Enable()
end)
My guess is that the
local Controls = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule")):GetControls()
Controls:Disable()
is the main problem, but at this point I am at a loss.
Any help is appreciated.
Thanks

2 comments
No, the only ones that were not local weren't inside a function or if statement or loop.
oh ok