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

"Unable to cast value to object" Shop gui not working?

Asked by
Time_URSS 146
5 years ago
Edited 5 years ago

Greetings,

I've been making a shop gui with some gamepasses in, and it should detect if it's a gamepass or not. The problem is that I get an error and I don't know how to solve it. Here are the scripts:

Leaderstats & Events script

01local MarketPlaceService = game:GetService("MarketplaceService")
02local player = game.Players.LocalPlayer
03local HasGamepass
04 
05game.Players.PlayerAdded:Connect(function(plr)
06    local leaderstats = Instance.new("Folder",plr)
07    leaderstats.Name = "leaderstats"
08 
09    local Coins = Instance.new("IntValue",leaderstats)
10    Coins.Name = "Coins"
11    Coins.Value = 10000
12end)
13 
14game.ReplicatedStorage.GetInfo.OnServerInvoke = function(player,name)
15    return game.ServerStorage.ShopItems[name].Coins.Value,game.ServerStorage.ShopItems[name].IsGamepass.Value,game.ServerStorage.ShopItems[name].GamepassID.Value
View all 47 lines...

Select Gun Script

01local MarketPlaceService = game:GetService("MarketplaceService")
02local ReplicatedStorage = game:GetService("ReplicatedStorage")
03local ServerStorage = game:GetService("ServerStorage")
04local ToolNameText = script.Parent.ToolName
05local ToolNameDesc = script.Parent.Description
06local Information = script.Parent.Parent.Parent.Parent.Information
07 
08ToolNameText.Text = tostring(ToolNameText.ToolName.Value)
09ToolNameDesc.Text = "Description: " .. tostring(ToolNameDesc.Description.Value)
10 
11script.Parent.MouseButton1Click:Connect(function(player)
12    local Price,BoolGamepass,GamepassID = ReplicatedStorage.GetInfo:InvokeServer(tostring(ToolNameText.ToolName.Value))
13 
14    if Price ~= nil then
15        Information.ToolName.Text = tostring(ToolNameText.ToolName.Value)
View all 24 lines...

Buy with Rubles Script

01local MarketPlaceService = game:GetService("MarketplaceService")
02local ReplicatedStorage = game:GetService("ReplicatedStorage")
03local ServerStorage = game:GetService("ServerStorage")
04local Information = script.Parent.Parent
05local ToolNameText = Information.ToolName.ProductName
06local ToolNameDesc = Information.ToolPrice.ProductPrice
07 
08ReplicatedStorage.BuyProcess.Event:Connect(function(name,price)
09    repeat wait(0.1) until script.Parent.MouseButton1Click
10    script.Parent.MouseButton1Click:Connect(function(player)
11        local Success = ReplicatedStorage.CheckSale:InvokeServer(name,nil,nil)
12 
13        if Success == true then
14            print("Purchase success!")
15        elseif Success == false then
16            print("Not enough money!")
17        end
18    end)
19end)

Buy with Robux script

01local MarketPlaceService = game:GetService("MarketplaceService")
02local ReplicatedStorage = game:GetService("ReplicatedStorage")
03local ServerStorage = game:GetService("ServerStorage")
04local Information = script.Parent.Parent
05local ToolNameText = Information.ToolName.ProductName
06local ToolNameDesc = Information.ToolPrice.ProductPrice
07local player = game.Players.LocalPlayer
08local HasGamepass = false
09 
10ReplicatedStorage.BuyProcess.Event:Connect(function(toolName,price,boolGamepass,gamepassId)
11    repeat wait(0.1) until script.Parent.MouseButton1Click
12    script.Parent.MouseButton1Click:Connect(function()
13        if gamepassId == nil then
14            local Success = ReplicatedStorage.CheckSale:InvokeServer(toolName)
15 
View all 45 lines...

If you need the hierarchy of the gui and everything, ask me in the comments.

0
What line and what script is the error happening in? Try to post code only relevant to the problem. pidgey 548 — 5y
0
It errors in line 34, in the leaderstats script. Time_URSS 146 — 5y
0
PromptGamePassPurchase ( Instance player , int64 gamePassId ) - your first argument at line 34 is a number (player.UserId). This method requires a Player object, not a number. pidgey 548 — 5y
0
MarketPlaceService:PromptGamePassPurchase(player, gamepassId) pidgey 548 — 5y
View all comments (2 more)
0
I see Time_URSS 146 — 5y
0
Now the error is "Unable to cast Instance to int64" Time_URSS 146 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

MarketplaceService:PromptGamePassPurchase, this function takes Player Object as an argument and GamepassId, which means, that you should not pass UserId, instead you should just pass Player. like that

1MarketPlaceService:PromptGamePassPurchase(player,gamepassId)
0
Thank ou Time_URSS 146 — 5y
0
Wait, now I receive this error: Unable to cast Instance to int64 Time_URSS 146 — 5y
Ad

Answer this question