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

[Solved] Why does this print 'Unable to cast to Object?'

I have a game, where if the person is VIP and wins a round, it will give them their points, which is more than regular players. Though I am having an error come out in the output. 'Unable to cast to Object' on line 8. I'm not sure what this means or how to fix it. Any help is appreciated, thanks.

Edit: I have now solved this, I did this by changing line 8 to

if game:GetService("GamePassService"):PlayerHasPass(game.Players[v], gamepassId)  then

Code:

local gamepassId = 1109268370
local gemsOnWin = 10
local vipWin = gemsOnWin * 1.5

for i,v in pairs(_G.playersInGame) do
  if v ~= nil then
    status.Value = v..' is the winner!'
      if game:GetService("GamePassService"):PlayerHasPass(v, gamepassId)  then
        game.Players[v].leaderstats.Gems.Value = 			game.Players[v].leaderstats.Gems.Value + vipWin
        game.Players[v]:
      else
        game.Players[v].leaderstats.Gems.Value = game.Players[v].leaderstats.Gems.Value + gemsOnWin
        game.Players[v]:LoadCharacter()
       break
       end
    end
end

6 comments

1

have you tried print debugging?

0

Printing out values is the best way to find out what's going wrong.

0

I did printing, and it stopped at line 8. That's what was getting the error.

2

Im guessing that v is a string? if so then PlayerHasPass requires the player object not a string which would explain the error.

1

try using :PlayerHasPass(game.Players[v], gamepassId)

0

I literally just found that out myself haha. Thanks though.

1 answer

2 too many ends

2 comments

0

That's not the issue as this isn't the full code.

0

There is also the right amount of ends anyway.

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