"Unable to cast value to object" Shop gui not working?
Asked by
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
01 | local MarketPlaceService = game:GetService( "MarketplaceService" ) |
02 | local player = game.Players.LocalPlayer |
05 | game.Players.PlayerAdded:Connect( function (plr) |
06 | local leaderstats = Instance.new( "Folder" ,plr) |
07 | leaderstats.Name = "leaderstats" |
09 | local Coins = Instance.new( "IntValue" ,leaderstats) |
14 | game.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 |
18 | game.ReplicatedStorage.CheckSale.OnServerInvoke = function (player,name,boolGamepass,gamepassId) |
19 | local price = game.ServerStorage.ShopItems [ name ] .Coins.Value |
21 | if player.leaderstats.Coins.Value > = price then |
22 | if boolGamepass = = true then |
23 | local Pass,Error = pcall ( function () |
24 | HasGamepass = MarketPlaceService:UserOwnsGamePassAsync(player.UserId,gamepassId) |
28 | error ( "Failed while checking if player owned gamepass: " ..Error) |
31 | if HasGamepass = = false then |
32 | print (player.UserId,gamepassId) |
34 | MarketPlaceService:PromptGamePassPurchase(player.UserId,gamepassId) |
35 | elseif HasGamepass = = true then |
36 | game.ServerStorage.ShopItems [ name ] [ name ] :Clone().Parent = player.Backpack |
37 | game.ServerStorage.ShopItems [ name ] [ name ] :Clone().Parent = player.StarterGear |
39 | elseif boolGamepass = = false then |
40 | game.ServerStorage.ShopItems [ name ] [ name ] :Clone().Parent = player.Backpack |
Select Gun Script
01 | local MarketPlaceService = game:GetService( "MarketplaceService" ) |
02 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
03 | local ServerStorage = game:GetService( "ServerStorage" ) |
04 | local ToolNameText = script.Parent.ToolName |
05 | local ToolNameDesc = script.Parent.Description |
06 | local Information = script.Parent.Parent.Parent.Parent.Information |
08 | ToolNameText.Text = tostring (ToolNameText.ToolName.Value) |
09 | ToolNameDesc.Text = "Description: " .. tostring (ToolNameDesc.Description.Value) |
11 | script.Parent.MouseButton 1 Click:Connect( function (player) |
12 | local Price,BoolGamepass,GamepassID = ReplicatedStorage.GetInfo:InvokeServer( tostring (ToolNameText.ToolName.Value)) |
15 | Information.ToolName.Text = tostring (ToolNameText.ToolName.Value) |
16 | if BoolGamepass = = true then |
17 | Information.ToolPrice.Text = "Gamepass: " .. Price .. " R$" |
18 | ReplicatedStorage.BuyProcess:Fire(ToolNameText.ToolName.Value,Price,BoolGamepass,GamepassID) |
19 | elseif BoolGamepass = = false then |
20 | Information.ToolPrice.Text = tonumber (Price) |
21 | ReplicatedStorage.BuyProcess:Fire(ToolNameText.ToolName.Value,Price,BoolGamepass) |
Buy with Rubles Script
01 | local MarketPlaceService = game:GetService( "MarketplaceService" ) |
02 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
03 | local ServerStorage = game:GetService( "ServerStorage" ) |
04 | local Information = script.Parent.Parent |
05 | local ToolNameText = Information.ToolName.ProductName |
06 | local ToolNameDesc = Information.ToolPrice.ProductPrice |
08 | ReplicatedStorage.BuyProcess.Event:Connect( function (name,price) |
09 | repeat wait( 0.1 ) until script.Parent.MouseButton 1 Click |
10 | script.Parent.MouseButton 1 Click:Connect( function (player) |
11 | local Success = ReplicatedStorage.CheckSale:InvokeServer(name, nil , nil ) |
13 | if Success = = true then |
14 | print ( "Purchase success!" ) |
15 | elseif Success = = false then |
16 | print ( "Not enough money!" ) |
Buy with Robux script
01 | local MarketPlaceService = game:GetService( "MarketplaceService" ) |
02 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
03 | local ServerStorage = game:GetService( "ServerStorage" ) |
04 | local Information = script.Parent.Parent |
05 | local ToolNameText = Information.ToolName.ProductName |
06 | local ToolNameDesc = Information.ToolPrice.ProductPrice |
07 | local player = game.Players.LocalPlayer |
08 | local HasGamepass = false |
10 | ReplicatedStorage.BuyProcess.Event:Connect( function (toolName,price,boolGamepass,gamepassId) |
11 | repeat wait( 0.1 ) until script.Parent.MouseButton 1 Click |
12 | script.Parent.MouseButton 1 Click:Connect( function () |
13 | if gamepassId = = nil then |
14 | local Success = ReplicatedStorage.CheckSale:InvokeServer(toolName) |
16 | if Success = = true then |
17 | player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - price |
19 | ServerStorage.ShopItems [ toolName ] [ toolName ] :Clone().Parent = player.Backpack |
20 | elseif Success = = false then |
21 | print ( "Not enough money!" ) |
23 | elseif gamepassId ~ = nil then |
24 | print (player.UserId.. " - " ..gamepassId) |
26 | local Pass,Error = pcall ( function () |
27 | HasGamepass = MarketPlaceService:UserOwnsGamePassAsync(player.UserId,gamepassId) |
31 | error ( "Failed while checking if player owned gamepass: " ..Error) |
34 | print (toolName,boolGamepass,gamepassId) |
36 | local Success = ReplicatedStorage.CheckSale:InvokeServer(toolName,boolGamepass,gamepassId) |
38 | if Success = = true then |
39 | print ( "Purchase success!" ) |
40 | elseif Success = = false then |
41 | print ( "Not enough money!" ) |
If you need the hierarchy of the gui and everything, ask me in the comments.