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

How to make an onClick screen?

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

This seems to be working, In a localscript.

You were missing parenthesis on your call to Auth. The variable player was 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)

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