I want my projectile to shoot in my mouse’s direction, but it doesn’t work.
robloxapp-20230802-2250598.wmv (3.9 MB)
my code:
client:
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = game:GetService("Players").LocalPlayer
local sg = ReplicatedStorage:WaitForChild("Sounds")
local qtrigger = true
local mouse = player:GetMouse()
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then
return
end
if input.KeyCode == Enum.KeyCode.Q and qtrigger == true then
local scl = sg:WaitForChild("EQ"):Clone() ---sound
scl.Parent = player.Character
local dtime = ReplicatedStorage:FindFirstChild("Values"):FindFirstChild("qValue").Value ---delaytime
ReplicatedStorage:WaitForChild("Event"):WaitForChild("qattackevent"):FireServer(mouse.Hit.Position)
local animation = script:WaitForChild("q")
scl:Play()
local animationTrack = player.Character:WaitForChild("Humanoid"):LoadAnimation(animation)
animationTrack:Play()
---debounce
qtrigger = false
wait(dtime)
qtrigger = true
end
end)
server:
task.wait()
local rs = game:GetService("ReplicatedStorage")
local RaycastHitbox = require(rs.RaycastHitboxV4)
local event = rs:WaitForChild("Event")
local speed = 500
event:WaitForChild("qattackevent").OnServerEvent:Connect(function(player, mousePos)
event:FindFirstChild("qclient"):FireClient(player)
local character = player.Character
local p = rs:WaitForChild("Projectile"):Clone()
local root = character:FindFirstChild("HumanoidRootPart")
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bv.Velocity = CFrame.new(p.Position, mousePos).LookVector * speed
p.Parent = workspace
p.CFrame = root.CFrame
bv.Parent = p
game:GetService("Debris"):AddItem(p, 100)
-- below is just raycast don't need to care about it
local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {player.Character, p} --- remember to define our character!
Params.FilterType = Enum.RaycastFilterType.Exclude
local newHitbox = RaycastHitbox.new(p)
newHitbox.RaycastParams = Params
newHitbox.OnHit:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if hit == 'Head' then
hit.Parent:FindFirstChild("Humanoid"):TakeDamage("25")
else
hit.Parent:FindFirstChild("Humanoid"):TakeDamage("15")
end
end
p:Destroy()
end)
newHitbox:HitStart()
end)