Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
aindev 4
5 years ago

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

Log in to vote
1
Answered by 5 years ago

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}

0
correct. User#19524 175 — 5y
Ad

Answer this question