Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Unable to cast value to Object. My gamepass is not working. Please help? [SOLVED]

I try to create a gamepass that i can use in my game, but it doesnt work.

Here is the code

local gamepass = 10954412

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		if game:GetService("MarketplaceService"):PlayerOwnsAsset(player.userId, gamepass) then
			local h = character:WaitForChild("Humanoid")
			h.WalkSpeed = 50
		end
	end)
end)

the output says

Unable to cast value to Object

Script 'Workspace.GamePass', Line 5

1 answer


Your issue in your script is that in line 5 it should be UserId instead or userId.

This will work, my spelling maybe wrong.

local Id = ######### -- Enter Id Here.
game.Player.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		if game:GetService("MarkertPlaceService"):UserOwnsAsyncGamePass(Player.UserId, Id) then
			Character:FindFirstChild("Humanoid").WalkSpeed = 50
		end
	end)
end)

If you want to give yourself specifically speed then you can just do the following...

game.Player.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		if Player.Name == "YOUR NAME HERE" then
			Character:FindFirstChild("Humanoid").WalkSpeed = 50
		end
	end)
end)

1 comment

0

Thankyou for your reply

This discussion is preserved as it was. New answers, comments, and votes are closed.