Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Game breaks when player leaves with tool on and car connected?

Help I'm trying to make an RC car game but I found a game breaking bug that caused the game to shut down, when you leave the game the car stays connected to nothing, which makes the car unusable. Is there a way to fix this?

local value = script.Parent.VehConnected
local tool = script.Parent

tool.Unequipped:Connect(function()
	if value.Value ~= nil then
		local FLmount = value.Value:FindFirstChild("FLWHEELMOUNT")
		local FRmount = value.Value:FindFirstChild("FRWHEELMOUNT")
		local RLmount = value.Value:FindFirstChild("RLWHEELMOUNT")
		local RRmount = value.Value:FindFirstChild("RRWHEELMOUNT")
		if FLmount ~= nil then
			FLmount.CylFL.AngularVelocity = 0
		end
		if FRmount ~= nil then
			FRmount.CylFR.AngularVelocity = 0
		end
		if RLmount ~= nil then
			RLmount.CylRL.AngularVelocity = 0
		end
		if RRmount ~= nil then
			RRmount.CylRR.AngularVelocity = 0
		end
		wait(0.1)
		print("Remote unequipped with vehicle connected, disconnecting...")
		value.Value.RemoteControlConnected.Value = false
		wait(0.1)
		value.Value = nil
		tool.SignalReceive.Disabled = true
		tool.Controllers:ClearAllChildren()
		if tool.Parent.Name == "Backpack" then
			local plr = tool.Parent.Parent.Name
			local plrcharacter = game.Workspace:FindFirstChild(plr)
			plrcharacter.Humanoid.JumpPower = 50
		else
			tool.Parent.Humanoid.JumpPower = 50
		end
	else
		script.Parent.Handle.Part.Text.Value = ""
	end
end)

2 comments

0

Try making it unequip whenever you leave the game?

0

I don't know howt o do that

1 answer

try and add a local script in StarterPlayerScripts that is like this?

game.Players.PlayerRemoving:Connect(function(player) --calls function when player leaves
	player.CharacterRemoving:Connect(function(character)
		character.Humanoid:UnequipTools()
	end)
end)

6 comments

0

Doesn't work.

0

oof

0

tried something different. Does this work?

0

still doesn't work.

0

still doesn't work.

0

then unequipping before leaving isn't the way

This discussion is preserved as it was. New answers, comments, and votes are closed.