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

Why is the local script not seeing the function?

Asked by 10 years ago

I have a localscript, and the first line is getmousething(). Later in the script, I have:

function getmousething()
    local player = game.Players.LocalPlayer
    local mouse = player:GetMouse()
    mouse.KeyDown:connect(function(key)
        if key.Byte == 102 then
            print 'F presseed'
        end
    end)
end

The error message is attempt to call global 'getmousething' (a nil value). Why can't it find that function?

2 answers

Log in to vote
1
Answered by 10 years ago

This might fix it.

function getmousething()
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.KeyDown:connect(function(key)
if key.Byte == 102 then
print 'F presseed'
end
end)
end
getmousething() -- Roblox must read the function before having it be called.

--You said that you ran it before it was called, Like above the function which would have been the error you got.

Ad
Log in to vote
0
Answered by 10 years ago

Roblox reads or loads everything in a script from Top to Bottom. So if your first line of Code is the call for the function, It hasn't read the function yet so it calls an error.

Try putting your call right under the function, or at the very bottom of the script.

0
I'll try something to fix it I guess CardboardRocks 215 — 10y
0
This is incorrect. If you have a function present anywhere within the script, it will fun the function. People put them at the top purely for convenience. Necrorave 560 — 10y
0
Why did i get a negative point for telling you the correct answer... Go ask anybody else and they'll say im right. Just trying to help :l kevinjurden 10 — 10y
0
Alright if you think your right, Go make a function that is at the bottom of your script and put the caller at the top.. I just tested this 2 minutes ago and it called an error because the function was nil.... kevinjurden 10 — 10y
0
@Necrorave Not true, Kevin is correct. I had a problem calling a function inside a function because the function being called was below the function that called the other one. Spongocardo 1991 — 10y

Answer this question