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

How to make an onClick screen?

Asked by 9 years ago

I am making a game where when you press the screen (textButton) the number goes up. Here is the explorer.

StarterGui > TextLabel > Value

TextButton > LocalScript

the error is ... :9: attempt to index global 'script' (a nil value) here is the script to make in IntValue go up,

local pass = 182358984
local number = 0
local upgrade = 1

function Auth(player)
    return game:GetService("GamePassService"):PlayerHasPass(player, pass)
end

script.Parent.MouseButton1Click:connect(function()
    if Auth then
        local upgrade = 3
    end
    number = number + upgrade
    script.Parent.Parent.TextLabel.Value.Value = "".. number
end)

1 answer

Log in to vote
0
Answered by 9 years ago

This seems to be working, In a localscript.

You were missing parenthesis on your call to Auth. The variable playerwas undefined. When the player has the pass it created a local variable so it could not be used outside of that scope.

local pass = 182358984
local number = 0
local upgrade = 1
local player = game.Players.LocalPlayer

function Auth()
    return game:GetService("GamePassService"):PlayerHasPass(player, pass)
end

script.Parent.MouseButton1Click:connect(function()
    if Auth() then --Missing ()
        upgrade = 3 --Was a local variable
    end
    number = number + upgrade
    script.Parent.Parent.TextLabel.Value.Value = number
end)

Ad

Answer this question