--[[ LawlR fix ]]
--

local ds = game:GetService("Debris")
local ps = game:GetService("Players")

wait(1)

local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local mousePosRemote = tool.RemoteFunction
local hitScript = tool.HitScript
local throwSound = handle.Throw
local hitSound = handle.Hit
local mesh = handle.Mesh

local cooldown = .4
local vel = 80

local db
local plr, chr, hum

local star = Instance.new("Part")
star.Name = "Ninjastar"
star.Shape = Enum.PartType.Block
star.Material = Enum.Material.Plastic
star.TopSurface = Enum.SurfaceType.Smooth
star.BottomSurface = Enum.SurfaceType.Smooth
star.FormFactor = Enum.FormFactor.Custom
star.Size = Vector3.new(1, 0.4, 1)
star.CanCollide = true
star.Locked = true
mesh:Clone().Parent = star
hitSound.Parent = star
hitScript.Parent = star
hitScript.Disabled = false


local function shoot(pos)
	handle.Transparency = 1
	throwSound:Play()

	local dir = CFrame.new(handle.Position, pos)
	local from = (handle.CFrame + dir.LookVector * 10)

	local star = star:clone()
	star.CFrame = CFrame.new(from.Position)
	star.Velocity = (dir.LookVector * vel)

	local force = Instance.new("BodyForce")
	force.Force = Vector3.new(0, 40, 0)

	local ownerTag = Instance.new("ObjectValue")
	ownerTag.Name = "Owner"
	ownerTag.Value = plr
	ownerTag.Parent = star
	
	force.Parent = star
	star.Parent = workspace
end


tool.Activated:Connect(function()
	if not db and plr then
		db = true
		tool.Enabled = false
		local pos = mousePosRemote:InvokeClient(plr)
		if pos and typeof(pos) == "CFrame" then
			shoot(pos.Position)
		end
		wait(chr:FindFirstChild("NinjaMaskOfLight") and cooldown/2 or cooldown)
		handle.Transparency = 0
		db = false
		tool.Enabled = true
	end
end)

tool.Equipped:Connect(function()
	local tempChr = tool.Parent
	local tempHum = tempChr:FindFirstChildWhichIsA("Humanoid")
	if tempHum then
		chr = tempChr
		hum = tempHum
		plr = ps:GetPlayerFromCharacter(tempChr)
	end
end)
