here is the local script for my knife the throwing doesn’t work it clones sword but doesn’t throw it it just makes the clone fall into the ground:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local throwEvent = ReplicatedStorage:WaitForChild("ThrowKnifeEvent")
uis = game:GetService("UserInputService")
knife = script.Parent
-- Function to handle mouse input for throwing
local function throwKnife()
local mouse = game.Players.LocalPlayer:GetMouse()
local targetPosition = mouse.Hit.Position
local cloned = knife.Mesh:Clone()
cloned.Parent = workspace
local bodyang = Instance.new("LinearVelocity", cloned)
cloned.Velocity = knife.CFrame.LookVector * 100
throwEvent:FireServer(targetPosition)
end
-- Example: Throw knife when 'E' key is pressed
uis.InputBegan:Connect(function(inp, gpe)
if inp.KeyCode == Enum.KeyCode.E then
throwKnife()
end
end)
and serverscript doesn’t work from leg to head:
local Knife = script.Parent
-- Function to handle knife throwing
local function throwKnife(player, targetPosition)
local knifeClone = Knife:Clone()
knifeClone.Parent = workspace
-- Set initial position and orientation
knifeClone.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position, targetPosition)
knifeClone.Touched:Connect(function(hit)
if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
-- Handle damage or hit effects here
hit.Parent.Humanoid:TakeDamage(50)
knifeClone:Destroy()
end
end)
end
-- RemoteEvent to receive throw requests from clients
local throwEvent = Instance.new("RemoteEvent")
throwEvent.Name = "ThrowKnifeEvent"
throwEvent.Parent = game.ReplicatedStorage
-- Handle throw requests from clients
throwEvent.OnServerEvent:Connect(function(player, targetPosition)
throwKnife(player, targetPosition)
end)
even hitting doesn’t work please fix it i need the help