Unable to cast value to int64,

Hello, im trying to ake my own gamepass tool script, but when i tried, it gave me the error in the title.

Code

local id = "11561701"
local mps = game:GetService("MarketplaceService")

game.Players.PlayerAdded:Connect(function(player)
	if mps:UserOwnsGamePassAsync(player,id) then
		game.Lighting.butterscotchPie:Clone().Parent = player.Backpack
	end
end)

You made the variable id into a string when it requires an int64.

The first argument is the userId of the player and you’re supplying it with the player object itself. Try this instead.

local id = 11561701
local mps = game:GetService("MarketplaceService")

game.Players.PlayerAdded:Connect(function(player)
	if mps:UserOwnsGamePassAsync(player.UserId, id) then
		game.Lighting.butterscotchPie:Clone().Parent = player.Backpack
	end
end)

No error, but no tool. Im new to scripting, sorry.

Make sure it is a server script (not LocalScript) and put it in a place where server scripts can run, like ServerScriptService

It is a serverscript, i will put it in serverscriptservice to see if that makes a diffrence.

If you want to give the player a tool each time they spawn in then you need to use the CharacterAdded event. Also use ServerStorage or ReplicatedStorage instead of lighting.

local id = 11561701
local mps = game:GetService("MarketplaceService")

function OnPlayerAdded(player)
    local function OnCharacterAdded(char)
        if mps:UserOwnsGamePassAsync(player.UserId, id) then
            game.Lighting:WaitForChild("butterscotchPie"):Clone().Parent = player.Backpack;
        end
    end

    OnCharacterAdded(player.Character or player.CharacterAdded:Wait());
    player.CharacterAdded:Connect(OnCharacterAdded);
end

for i,v in ipairs(game.Players:GetPlayers()) do OnPlayerAdded(v) end

game.Players.PlayerAdded:Connect(OnPlayerAdded);
1 Like

Thanks so much! This worked! :slight_smile:

1 Like