Hello everyone,
I am experiencing a very specific problem. I am attempting to make a realistic fire system where the player must connect the firetruck to a hydrant in order to refill the truck and get water, etc.
The issue I am having is whenever the player connects the input hose from the truck to the output part of the hydrant, roblox studio completely freezes and crashes. It is similar to when you forget to put a wait()
inside a while true do, except it doesn’t return an error about script overload; it just crashes after 3 minutes.
In order to allow you to understand this code, I’ll explain some of it. Basically, when the player connects the hose to the hydrant, first it checks if the hydrant is connected already so that if it is already connected, it will disconnect and vice versa. Second, it checks if they are holding the connecting hose tool. If yes, it proceeds to clone all the parts of the tool into a model and then deletes the tool from the players inventory so that visually it appears to be connected without having to keep holding the tool.
After it makes the tool a model and removes it from your backpack, it fires a regular event to the script on the truck (script 2) that gives the player the input hose. The variables that are passed through are the name of the hydrant that the truck is connected to (e.g City_Hydrant_1) and something called a “vType” which stands for value type. The value type tells the script to either connect or disconnect the hose.
Script One:
local tName = "TestConnector"
local connected = false
local vType --1 is value true, 2 is value false
local db = false
local dbw = 1
--local db1 = false
--local dbw1 = 1
script.Parent.PromptButtonHoldEnded:Connect(function(player)
wait()
if connected == false then
print(player)
print(player.Name)
--local char = game.Workspace:FindFirstChild(player)
local char = game.Workspace:FindFirstChild(player.Name)
print(char.Name)
local Tool = char:FindFirstChild(tName)
local character = Tool.Parent
local player1 = workspace:FindFirstChild(character.Name)
local endSeg = Tool:FindFirstChild("Handle")
local connected1 = Tool:FindFirstChild("Connected")
endSeg.Anchored = true
endSeg.Position = script.Parent.Parent.Parent.Proxy.Position
connected1.Value = true
local model = Instance.new("Model")
model.Name = "ConnectorHoseModel_"..character.Name
model.Parent = workspace
local clone = Tool:Clone()
for _, child in pairs(clone:GetChildren()) do
child.Parent = model
end
for _, child in pairs(clone:GetChildren()) do
child.Parent = model
end
print("completed all that")
endSeg.Parent:Destroy()
local name = script.Parent.Parent.Parent.Name
vType = 1
if db == false then
db = true
game.ReplicatedStorage:FindFirstChild("Events"):FindFirstChild("FireSystem"):FindFirstChild("HydrantConnectedTo"):Fire(name, vType)
print('event fired')
connected = true
else
wait(dbw)
db = false
end
print("done everything w/o crashing")
--model:FindFirstChild("Connected").Value = true
elseif connected == true then
workspace:FindFirstChild("ConnectorHoseModel_"..player.Name):Destroy()
local name = ""
vType = 2
--if db1 == false then
-- db1 = true
game.ReplicatedStorage:FindFirstChild("Events"):FindFirstChild("FireSystem"):FindFirstChild("HydrantConnectedTo"):Fire(name, vType)
connected = false
--else
-- wait(dbw1)
-- db1 = false
--end
end
end)
Script Two
local tName = "TestConnector"
local toolLoc = game:GetService("ServerStorage"):FindFirstChild("Tools"):FindFirstChild("TestConnector")
local connected = false
local db = false
local dbw = 0.2
script.Parent.PromptButtonHoldEnded:Connect(function(player)
if db == false then
db = true
local playerService = game:GetService("Players"):FindFirstChild(player.Name)
local char = workspace:FindFirstChild(player.Name)
local hum = char:FindFirstChild("Humanoid")
local backpack = playerService:FindFirstChild("Backpack")
local clone = toolLoc:Clone()
clone.Parent = backpack
hum:EquipTool(clone)
clone:FindFirstChild("Hose_End").Anchored = true
clone:FindFirstChild("Hose_End").Position = script.Parent.Parent.Position
else
wait(dbw)
db = false
end
end)
game.ReplicatedStorage:FindFirstChild("Events"):FindFirstChild("FireSystem"):FindFirstChild("HydrantConnectedTo").Event:Connect(function(name, vType)
print('workin')
script.Parent.Parent.Parent.ConnectedTo.Value = name
if vType == 1 then
script.Parent.Parent.Parent.Connected.Value = true
print(script.Parent.Parent.Parent.Connected.Value)
elseif vType == 2 then
script.Parent.Parent.Parent.Connected.Value = false
print(script.Parent.Parent.Parent.Connected.Value)
end
print(script.Parent.Parent.Parent.ConnectedTo.Value)
end)
I believe the problem is something to do with the event being received because I was able to make the script print print("done everything w/o crashing")
before studio crashed (how ironic).