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

Can anyone help me with firing a projectile?

So it's saying the issue is with "local mouse = player.GetMouse()" but I have no clue how to fix it. Any ideas?

uis = game:GetService("UserInputService")

plr = game.Players.LocalPlayer

local mouse = player:GetMouse()

handle = tool:WaitForChild("Handle")

tool = script.Parent

tool.Activated:Connect(function()

local Part = Instance.new(Part,"workspace")

Part.Name = "Paper Dart"

Part.BrickColor = BrickColor.White()

Part.Size = Vector3.new(1,1,3)

Part.Material = "Plastic"

Part.Shape = "Block"

Part.TopSurface = "smooth"

Part.BottomSurface = "smooth"

Part.CFrame = handle.CFrame * CFrame.new(0,0,-5)

Part.Velocity = handle.CFrame.LookVector *400 


if mouse.Target and mouse.Target.Parent : FindFirstChild('Humanoid') then
	game.Players.LocalPlayer.Character.Humanoid:TakeDamage(20)
end

end)

2 answers

Btw this is the error code I'm getting:

Players.ThatDummerGuy.Backpack.Origami.LocalScript:3: attempt to index nil with 'GetMouse'

Origami is the name of the tool that this code is binded to

player isn't game.Players.LocalPlayer. Try doing this instead:

uis = game:GetService("UserInputService")

player = game.Players.LocalPlayer

local mouse = player:GetMouse()

handle = tool:WaitForChild("Handle")

tool = script.Parent

tool.Activated:Connect(function()
	local Part = Instance.new(Part,"workspace")

	Part.Name = "Paper Dart"
	
	Part.BrickColor = BrickColor.White()
	
	Part.Size = Vector3.new(1,1,3)
	
	Part.Material = "Plastic"

	Part.Shape = "Block"

	Part.TopSurface = "smooth"

	Part.BottomSurface = "smooth"

	Part.CFrame = handle.CFrame * CFrame.new(0,0,-5)

	Part.Velocity = handle.CFrame.LookVector *400 


	if mouse.Target and mouse.Target.Parent : FindFirstChild('Humanoid') then
    		mouse.Target.Humanoid:TakeDamage(20)
	end
end)

Hope this helps!

2 comments

0

I just noticed, isn't this weapon going to damage yourself instead of the target? (line 34 is referencing localplayer.Character instead of the target)

0

fixed

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