Hello there; title really says it all.
The result I want from the system is for the raycast to properly go to the mouse’s cursor, but it instead goes behind the player;
Client
local event = script.Parent:WaitForChild("a")
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button1Down:Connect(function()
event:FireServer(mouse.Hit.p)
end)
Server
local remoteEvent = script.Parent.a
local tool = script.Parent
-- min
-- max
min, max = 10, 20
local function takeDamage(humanoid)
local random = math.random(min, max)
humanoid.Health -= random
end
remoteEvent.OnServerEvent:Connect(function(plr, mouseHit)
local startPosition = script.Parent.Handle.CFrame.Position
local endPosition = mouseHit
local newPos = (startPosition - endPosition)
local rayParams = RaycastParams.new()
rayParams.FilterDescendantsInstances = tool.Parent:GetDescendants()
local rayCast = workspace:Raycast(startPosition, newPos)
if rayCast then
if rayCast.Instance.Parent:FindFirstChild("Humanoid") then
local a = tool.Handle:Clone()
a.Name = "mousePart"
a.Position = rayCast.Position
a.Anchored = true
a.Parent = workspace
takeDamage(rayCast.Instance.Parent:FindFirstChild("Humanoid"))
end
end
end)
yes i do know about the fact this can be mass spammed; i just want to fix the raycasting first