Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is my bow not damaging people?

Okay so I am making a bow that shoots a beam once fired. The local script that fires the bow works but the damage script isn't working. The damage script is not a local script. I am using mouse.Target to determine what happens. Here is the damage script:

local playerName = script.Parent.Parent.Parent.Name
	print(playerName)
	local player = game:GetService("Players"):FindFirstChild(playerName)
	local mouse = player:GetMouse()
script.Parent.Activated:Connect(function()
local humanoid = mouse.Target.Parent:FindFirstChild("Humanoid")
	if humanoid then
		humanoid:TakeDamage(10)
	end
end)

I put this in the local script at first and it was just fine but as soon as I made it its own script it wouldn't work. There are no errors I am just really confused. Thanks in advance!

3 comments

0

There is an error message actually: Players.TheHideousGloom.Backpack.Bow.Script:6: attempt to index nil with 'Target'

0

instead of doing :findfirstchild() do Mouse.Target filter

1 answer

I figured it out with some really nice help from the discord community. I used a RemoteEvent and triggered it with mouse.Target as a parameter. Then used that to deal the damage. Using a server script I waited for the event to trigger using game.ReplicatedStoragte.RemoteEvent.OnServerFired:Connect(function(player,mouse.Target)

end)

This discussion is preserved as it was. New answers, comments, and votes are closed.