I have a throwable grenade that you can throw. And it seems fine, but when I try to throw it after player dies it gives me error like this (and somewhy gives it twice):
Local script:
local cas = game:GetService("ContextActionService")
local tool = script.Parent
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAppearanceLoaded:Wait()
local event = tool:FindFirstChild("ThrowEvent")
local part = tool:FindFirstChild("Handle")
local function bindFunc()
local mouse = player:GetMouse()
event:FireServer(mouse.Hit.Position, part)
player.CameraMode = Enum.CameraMode.Classic
end
tool.Equipped:Connect(function()
player.CameraMode = Enum.CameraMode.LockFirstPerson
cas:BindAction("Throw", bindFunc, true, Enum.UserInputType.MouseButton1)
end)
tool.Unequipped:Connect(function()
player.CameraMode = Enum.CameraMode.Classic
cas:UnbindAction("Throw")
end)
Server script:
local tool = script.Parent
event.OnServerEvent:Connect(function(player, pos, p)
local part = p:Clone()
part.Parent = workspace
part.CanCollide = true
part.CFrame = CFrame.lookAt(part.Position, pos)
part.AssemblyLinearVelocity = part.CFrame.LookVector * 70
tool:Destroy()
end)
Photo in explorer: