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

Why does this gun script not go to the mouse position?

I looked up how to and it didn't work.

target = game.Players.LocalPlayer:GetMouse().Hit
function activated()
	local gunharm = Instance.new("Part", workspace)
	gunharm.Size = Vector3.new(2.61, 0.38, 0.37)
	gunharm.Touched:connect(function(hit)
		hit.Parent.Humanoid.Health = 0
	end)
	gunharm.Material = Enum.Material.Neon
	gunharm.BrickColor = BrickColor.new("CGA brown")
	gunharm.Name = 'gunharm'
	game.Workspace.gunharm:MoveTo(Vector3.new(target))
	wait(.8)
	gunharm:Destroy()
end

script.Parent.Activated:Connect(activated)

1 answer

Just letting you know, this is a perfect opportunity to practice script analyzing through the output box and print debugging. Anyways, you have to set target while inside the function. Currently, mouse.Hit is assigned to the place it was first called.

For a better explanation: Lets say target was assigned to {0,0,0} at run time, when you called the function, Target has not been reassigned so the target position is still at {0,0,0}

1 comment

0

correct.

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