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

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

Asked by 3 years ago
Edited 3 years ago

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

Log in to vote
0
Answered by 3 years ago

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)
0
Thankyou for your reply Blackbooks 138 — 3y
Ad

Answer this question