Issue with my gun

recently i made a tool have a gun inside of it when i made script which i saw on one of alvin blox videos it didnt work i dont know why i did every thing in the video but it didnt work
Script
–script.Parent.Fire.OnServerEvent:Connect(function(player,mousePos)

local p = RaycastParams.new()
p.FilterDescendantsInstances = (player.Character)
p.FilterType = Enum.RaycastFilterType.Blacklist

local re = workspace:Raycast(script.Parent.Pistol.Model.Aim_Sight.Pat.Position,(mousePos - script.Parent.Handle.Position)*400,p)

if re then
	local hi = re.Instance
	local mo = hi:FindFirstAncestoOfClass("Model")
	
	if mo then
		if mo:FinFirstChild("Humanoid") then
			mo.Humanoi.Health -= 30
		end
	end
end

end)

Local script

–local mouse = game.Players.LocalPlayer:GetMouse()

mouse.Button1Down:Connect(function()
script.Parent.Fire:FireServer(mouse.Hit.p)
end)–

Fire is a RemoteEvent
I hope someone help with the script

I think you spelled Humanoid wrong.

Oh if thats what i have done its a big mistake i guess

1 Like

i fixed that but still didnt work

Are there any errors? It’s hard to know what the problem actually is

yeah only this one

Unable to cast value to Objects - Server - Script:4

1 Like

I see the problem, change this line to
p.FilterDescendantsInstances = {player.Character}

(you’re using the incorrect brackets)

i tried it says not valid member of work space
maybe the code dont work on dummy?

–p.FilterDescendantsInstances = {player.Character}–

is that means only players can get damage?

1 Like

This line makes it so that your raycast will ignore your character, so in your case that would be for you to not damage yourself.

Please send the new error and your current script

this is the script
script.Parent.Fire.OnServerEvent:Connect(function(player,mousePos)

local p = RaycastParams.new()
p.FilterDescendantsInstances = {player.Character}
p.FilterType = Enum.RaycastFilterType.Blacklist

local re = workspace:Raycast(script.Parent.Pistol.Model.Aim_Sight.Pat.Position,(mousePos - script.Parent.Handle.Position)*400,p)

if re then
	local hi = re.Instance
	local mo = hi:FindFirstAncestoOfClass("Model")
	
	if mo then
		if mo:FinFirstChild("Humanoid") then
			mo.Humanoid.Health -= 30
		end
	end
end

end)

This is the error
FindFirstAncestoOfClass is not a valid member of Part “Workspace.Test Dummy.Torso”

1 Like

Another typo

change it to

local mo = hi:FindFirstAncestorOfClass(“Model”)

yeah thats work and i got another error same issue missing letters thanks for your help

1 Like