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

Why will my script not work when it is formatted correctly?

So I'm making a clicking simulator, with gamepasses that increase the click increment value. I have an IntValue which tells the game what the Click Increment is.

My script,

local IncVal = script.Parent.IncrementValue.Value
local Gamepass2xClicksID = 12345 -- TempValue
local Gamepass5xClicksID = 123456 -- TempValue
local Gamepass10xClicksID = 1234567 -- TempValue
local Player = game.Players.LocalPlayer
local IncVal = 1

if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player, Gamepass2xClicksID) then
	IncVal = 2
elseif game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player, Gamepass5xClicksID) then
	IncVal = 5
elseif game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player, Gamepass10xClicksID) then
	IncVal = 10

script.Parent.MouseButton1Click:Connect(function()
	Player.leaderstats.Clicks.Value = game.Players.LocalPlayer.leaderstats.Clicks.Value + IncVal
	end)
end

is correct, no errors. However, when I play the game, I get the Output error of:

Unable to cast Instance to int64

How can I fix this?

1 answer

✓ Accepted answer

So the error here is that to check if the player has the gamepass you must provide the player's user id and the gamepass id.

Here's the adjusted script:

local IncVal = script.Parent.IncrementValue.Value
local Gamepass2xClicksID = 12345 -- TempValue
local Gamepass5xClicksID = 123456 -- TempValue
local Gamepass10xClicksID = 1234567 -- TempValue
local Playerid = game.Players.LocalPlayer.UserId -- user id of the player
local Player = game.Players.LocalPlayer
local IncVal = 1

if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Playerid, Gamepass2xClicksID) then
    IncVal = 2
elseif game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Playerid, Gamepass5xClicksID) then
    IncVal = 5
elseif game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Playerid, Gamepass10xClicksID) then
    IncVal = 10

script.Parent.MouseButton1Click:Connect(function()
    Player.leaderstats.Clicks.Value = game.Players.LocalPlayer.leaderstats.Clicks.Value + IncVal
    end)
end

Hope this helped!

Any questions? Just ask!

1 comment

0

Thanks, let me try this out and I'll update you on it.

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