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?
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!