Script inside tool stop after moving it

So i have a custom toolbar and it works fine same with custom tool events BUT if a script is still running while the tool get unequipped (Move out of the character and go to a folder inside the player) every script stop midway
Here some screens also i get no errors

Local:

local Players = game:GetService("Players")
local Uis = game:GetService("UserInputService")

local Player = Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()

local Debounce = false

local Bind = script.Parent.Bind

local Activate = Bind:FindFirstChild("Use")
local Equipped = Bind.Equip
local Unequipped = Bind.Unequip

local Event = script.Parent.Event

Uis.InputBegan:Connect(function(Input,Obj)
	if Input.UserInputType == Enum.UserInputType.MouseButton1 then
		Activate:Fire()
	end
end)	

Activate.Event:Connect(function()
	if Debounce == false then 
		Debounce = true
		if script.Parent:WaitForChild("Equipped").Value == true then
			Event:FireServer()
		end
		wait(15)
		Debounce = false
	end
end)

Server:

local RepStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")

local Assets = RepStorage:WaitForChild("Assets")
local Event = script.Parent:WaitForChild("Event")

local Active = false

Event.OnServerEvent:Connect(function(Player)
	local Char = Player.Character
	local HMR = Char.HumanoidRootPart
	
	script.lightning_strike:Play()
	
	local ThunderPillar = Assets:WaitForChild("ThunderPillar"):Clone()
	local ThunderSphere = Assets:WaitForChild("ThunderSphere"):Clone()
	ThunderPillar.Position = HMR.Position + Vector3.new(0,20,0)
	ThunderSphere.Position = HMR.Position
	ThunderPillar.Parent = workspace
	ThunderSphere.Parent = workspace
	
	local Info = TweenInfo.new(0.3,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,3)
	local Tween = TweenService:Create(ThunderPillar,Info,{Size = Vector3.new(60,10,10), Transparency = 0})
	local Tween2 = TweenService:Create(ThunderSphere,Info,{Size = Vector3.new(30,30,30), Transparency = 0})
	
	Tween:Play()
	Tween2:Play()
	
	
	local Power = Instance.new("BodyVelocity")
	Power.Velocity = Vector3.new(0,150,0)
	Power.MaxForce = Vector3.new(0,10000000,0)
	Power.Parent = HMR
	wait(0.3)
	Power:Destroy()
	wait(0.6)
	ThunderPillar:Destroy()
	ThunderSphere:Destroy()
end)

Screens and gif :
image
https://gyazo.com/1639280ebda66ca4c2b0abd3e3514e69
Normally it should’t fly forever if it wasn’t clear

1 Like

Bump, 20 views no reply, can someone tell me if you need more info and exactly what info?

I’m guessing the on server event gets destroyed after moving it so the connection breaks, try using debris to destroy the velocity instead:

local Debris = game:GetService("Debris")

	Debris:AddItem(Power, 0.3)
	Debris:AddItem(ThunderPillar, 0.8)
	Debris:AddItem(ThunderSphere, 2)

Otherwise yeah you described your problem already:

Something weird will happen when the script happens outside of these locations so why not just make a custom tool system without using the tool Instance?

The instant that the following conditions are met, a Script’s Lua code is run in a new thread:

  • Disabled property is false
  • The Script object is a descendant of the Workspace or
    ServerScriptService

Thanks, i was sleeping ill try it now and ill let you know

Yeah it works actually so thanks i guess i ddin’t remember of the existance of debris