How can I make a player's item in his hand not be deleted?

Local Script:

local uis = game:GetService("UserInputService")
local tool = script.Parent
local anim = tool:WaitForChild("Throw")
local track = nil
local event = tool:WaitForChild("ThrowingEvent")
local equipped = false
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local animator = hum:FindFirstChild("Animator") or Instance.new("Animator", hum)
local track = animator:LoadAnimation(anim)

local function throw()
	wait(0.5)
	event:FireServer()
end

uis.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		track:Play()
	end
	
	if input.UserInputType == Enum.UserInputType.Touch then
		track:Play()
	end
end)


mouse.Button1Down:Connect(throw)

Script:

local tool = script.Parent
local event = script.Parent:WaitForChild("ThrowingEvent")
local debris = game:GetService("Debris")

event.OnServerEvent:Connect(function(player)
	local dynamite = tool.Handle:Clone()
	dynamite.Parent = workspace
	dynamite.CanCollide = true
	local char = player.Character or player.CharacterAdded:Wait()
	local hrp = char:WaitForChild("HumanoidRootPart")
	local dir = hrp.CFrame.LookVector + hrp.CFrame.UpVector
	dynamite.VectorForce.Force = dir * 10
	tool:Destroy()
	wait(0.2)
	dynamite.VectorForce.Enabled = false
	wait(1.5)
	dynamite.ExploseSound:Play()
	
	local vfx = workspace.Explosion_1:Clone()
	vfx.Parent = workspace.vfx
	vfx.Position = dynamite.Position
	vfx.Anchored = true
	vfx.Attachment.Explosion.Enabled = true
	vfx.Attachment.Smoke.Enabled = true
	dynamite.Transparency = 1
	dynamite.Anchored = true
	dynamite.CanCollide = false
	debris:AddItem(dynamite, 2.2)
	
	wait(0.7)
	
	vfx:Destroy()
	
end)

So here’s what I have:

as you can see after you throw the dynamite disappears. The question is how to make it reappear in the hand and actually, the player can throw it again.
Снимок экрана 2023-06-27 в 12.45.17

tool:Destroy()

Remove this line from the server script. This will still make the tool appear in your hand tho. If you don’t want that, then replace the server script with this:

local tool = script.Parent
local event = script.Parent:WaitForChild("ThrowingEvent")
local debris = game:GetService("Debris")

local function ToggleVisibility(isVisible: boolean)
    local value = isVisible and 0 or 1

    for _, part in tool:GetDescenedants() do
		if part:IsA("BasePart") then
			part.Transparency = value
		end
	end
end

event.OnServerEvent:Connect(function(player)
	local dynamite = tool.Handle:Clone()
	dynamite.Parent = workspace
	dynamite.CanCollide = true
	local char = player.Character or player.CharacterAdded:Wait()
	local hrp = char:WaitForChild("HumanoidRootPart")
	local dir = hrp.CFrame.LookVector + hrp.CFrame.UpVector
	dynamite.VectorForce.Force = dir * 10
	
    ToggleVisiblity(false)
	task.wait(0.2)
	dynamite.VectorForce.Enabled = false
	task.wait(1.5)
	dynamite.ExploseSound:Play()
	
	local vfx = workspace.Explosion_1:Clone()
	vfx.Parent = workspace.vfx
	vfx.Position = dynamite.Position
	vfx.Anchored = true
	vfx.Attachment.Explosion.Enabled = true
	vfx.Attachment.Smoke.Enabled = true
	dynamite.Transparency = 1
	dynamite.Anchored = true
	dynamite.CanCollide = false
	debris:AddItem(dynamite, 2.2)
	
	task.wait(0.7)
	
	vfx:Destroy()
    ToggleVisibility(true)
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.