Hello! I’ve been trying to make a Viewmodel Shooter Game, the issue is that I made a script that doesn’t work, and I can’t quite tell what’s causing the script to malfunction…
The thing I want to achieve is that, if the cursor is pointing at a player or an NPC, it will damage the humanoid of the player/NPC. For some reason this doesn’t work, I’ve tried with MousePos, but it gave me an odd error
game.ReplicatedStorage.OnFire.OnServerEvent:Connect(function(player)
local endpart = game:GetService("ReplicatedStorage").Endpart.Value
local shootpart = game:GetService("ReplicatedStorage").Shootpart.Value
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {player.Character}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(shootpart.Position, (endpart.Position - shootpart.Position)*25, raycastParams)
if raycastResult then
local hitPart = raycastResult.Instance
local model = hitPart:FindFirstAncestorOfClass("Model")
if model then
if model:FindFirstChild("Humanoid") then
model.Humanoid.Health -=5
end
end
end
end)
This is the code that I made, I made two object values that starts from a point and end to another point, for some reason this doesn’t work.
If someone can find the issue it would be appreciated!