Unable to cast value to Object - Previously wasn't a problem

  1. What do you want to achieve?

I want my Stereo model (with a click detector inside) to bring up the GUI that allows a player with the stereo gamepass to play an audio for a certain sound area.

  1. What is the issue?

Previously this had worked, but now it’s somehow bugged so I’m unsure if it’s something that has changed!

  1. What solutions have you tried so far?

I checked output and it came up with the error “unable to cast value to object”. After looking around on the internet all the solutions I found didn’t seem to solve the issue.

script.Parent:WaitForChild("ClickDetector").MouseClick:Connect(function(player)
	
	if OwnsGamepass(player.UserId, 18243189) or PlayerIsWhitelisted(player) then
		player.PlayerGui.StereoGui.Enabled = true
	else
		game:GetService("ReplicatedStorage"):WaitForChild("Stereo"):FireClient(player)
	end
	
end)

This server script is inside the part that should be clicked alongside the click detector. There is more before this which addresses the gamepass and whitelist etc.

Not sure if it’s something super simple and I’ve completely dumbed out on this?

Thanks :slight_smile:

What are those?
Mind showing us those functions?
[And the client side aswell]

local MarketplaceService = game:GetService("MarketplaceService")

function OwnsGamepass(userId, gamepassId)
	local success,result = pcall(MarketplaceService.UserOwnsGamePassAsync, MarketplaceService, userId, gamepassId)
	if not success then
		result = false
	end
	return result
end

local whitelist = { "Naomicatlady3", "SirNebsalot", "asyIunz", "XxXMackenziee", "Verified_Players", "T3ddy_Bxar" }

function PlayerIsWhitelisted(player)
	for i, v in pairs(whitelist) do
		if v:lower() == player.Name:lower() then
			return true
		end
	end
	return false
end

script.Parent:WaitForChild("ClickDetector").MouseClick:Connect(function(player)
	
	if OwnsGamepass(player.UserId, 18243189) or PlayerIsWhitelisted(player) then
		player.PlayerGui.StereoGui.Enabled = true
	else
		game:GetService("ReplicatedStorage"):WaitForChild("Stereo"):FireClient(player)
	end
	
end)

This is the entirety of the server script. and here is the local script inside the GUI:

local MarketplaceService = game:GetService("MarketplaceService")

script.Parent.Play.MouseButton1Click:Connect(function()
	game:GetService("ReplicatedStorage").Stereo:FireServer(script.Parent.MusicIdFrame.Input.Text)
end)

script.Parent.Pause.MouseButton1Click:Connect(function()
	game:GetService("ReplicatedStorage").Stereo:FireServer("")
end)

game:GetService("ReplicatedStorage"):WaitForChild("Stereo").OnClientEvent:Connect(function()
	MarketplaceService:PromptGamePassPurchase(game:GetService("Players").LocalPlayer.UserId, 18243189)
end)

I’m just a bit confused since it has been working for ages and since it’s stopped it’s turned into a panic since people have spent money on this so it ideally needs to be sorted fast. so far I’ve temporarily disabled the gamepass for purchase due to this as I don’t want more people to buy it when it currently doesn’t work anymore!

any advice would be greatly appreciated. The script was made by a previous scripter for a game we both worked on. My knowledge on scripting isn’t too advanced, and the scripture has actually vanished completely so I cannot contact him!

at which line the error occurs?

Line 12 of the local script - I believe.

Here is the output:

remove .UserId because the function takes player and gamepass id as arguments

MarketplaceService:PromptGamePassPurchase(game:GetService("Players").LocalPlayer, 18243189)
2 Likes

Thanks so much! I had a sneaking suspicion it was to do with that, but it looks like my whitelist will no longer work because of this. Perhaps it’s due to a recent change since it’s happened with my other game passes too!