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

Why isn't this script working?

Asked by 9 years ago
local player = game.Players.LocalPlayer
local mouse = player.getMouse()

plr = game.Players.Player.Name:findFirstChild("Player")
pt1 = plr.Torso
mag = (pt1.Position - script.Parent.Position).magnitude
plr.Humanoid.Running:connect(function(speed)
print(mag)
if mag <= 15 then
    print(mag)

    end
end)

function getDistance()
    print ("h")
    return player.Character and player:DistanceFromCharacter(script.Parent.Position) or math.huge
end

while wait() do
    print ("1")
    if getDistance() < 20 then
       V=V+1
game.Workspace.TextValue.Value = V
print(V)
else 
    V=V-1
game.Workspace.TextValue.Value = V
    end
print(V)

end

I'm getting this error: Script:2: attempt to index local 'player' (a nil value)

1
player:GetMouse() not player.GetMouse() Discern 1007 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago
local player = game.Players.LocalPlayer
local mouse = player:GetMouse() -- You put Player.GetMouse(), it's player:GetMouse()

plr = game.Players.Player.Name:findFirstChild("Player")
pt1 = plr.Torso
mag = (pt1.Position - script.Parent.Position).magnitude
plr.Humanoid.Running:connect(function(speed)
print(mag)
if mag <= 15 then
    print(mag)

    end
end)

function getDistance()
    print ("h")
    return player.Character and player:DistanceFromCharacter(script.Parent.Position) or math.huge
end

while wait() do
    print ("1")
    if getDistance() < 20 then
       V=V+1
game.Workspace.TextValue.Value = V
print(V)
else 
    V=V-1
game.Workspace.TextValue.Value = V
    end
print(V)

end

Ad

Answer this question