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

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

Asked by
dxrrevn 13
3 years ago

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

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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!

0
Thanks, let me try this out and I'll update you on it. dxrrevn 13 — 3y
Ad

Answer this question