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

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

Asked by
awfulszn 394 Moderation Voter
6 years ago
Edited 6 years ago

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
1
have you tried print debugging? abnotaddable 920 — 6y
0
Printing out values is the best way to find out what's going wrong. Goulstem 8144 — 6y
0
I did printing, and it stopped at line 8. That's what was getting the error. awfulszn 394 — 6y
2
Im guessing that v is a string? if so then PlayerHasPass requires the player object not a string which would explain the error. User#5423 17 — 6y
View all comments (2 more)
1
try using :PlayerHasPass(game.Players[v], gamepassId) abnotaddable 920 — 6y
0
I literally just found that out myself haha. Thanks though. awfulszn 394 — 6y

1 answer

Log in to vote
-4
Answered by 6 years ago

2 too many ends

0
That's not the issue as this isn't the full code. awfulszn 394 — 6y
0
There is also the right amount of ends anyway. awfulszn 394 — 6y
Ad

Answer this question