Jackd44Join Date: 2008-12-19 Post Count: 200 |
So basically I'm trying to make it so a player has been chosen and their name is stored inside a variable named "NextIt"(Don't worry, I have set a path, it knows what NextIt is and where it is.) And soon through my script I get this error:Unable to cast value to Object
Script "Workspace.HideAndSeek", Line 130 - global Choose_It
Ok, so I gathered that it was around line 130, so I take a look there.
130-it = game.Players:playerFromCharacter(NextIt.Value)
131-m.Text = it.Name.." has been chosen! Because they bought the V.I.P room bonus!"
Now after lots of testing and messing around I couldn't understand what was going wrong. Does anyone know the answer? |
|
Jackd44Join Date: 2008-12-19 Post Count: 200 |
*Shame* Bump. |
|
DataStoreJoin Date: 2012-02-07 Post Count: 8540 |
'NextIt'
-> You've not told us it's 'ClassName'. Is it an ObjectValue, or..? |
|
Jackd44Join Date: 2008-12-19 Post Count: 200 |
Ah yes sorry, NextIt is a string value :) It has already been defined earlier in the script. |
|
DataStoreJoin Date: 2012-02-07 Post Count: 8540 |
The ':GetPlayerFromCharacter()' does not 'accept' a string value as an argument within the method. You have to give it a character object.
For example,
local Thing = game.Players:GetPlayerFromCharacter(Workspace.Player1)
|
|
Jackd44Join Date: 2008-12-19 Post Count: 200 |
Yeah, that was part of my playing around, I just have no idea how to use something similar to it with strings. :/ |
|
DataStoreJoin Date: 2012-02-07 Post Count: 8540 |
game.Players:playerFromCharacter(game.Players[NextIt.Value])
..? |
|
Jackd44Join Date: 2008-12-19 Post Count: 200 |
It's getting somewhere after using a bit of what you have posted it seemed to get past that line, then it gets on to the next line and crashes, I'm going to try and solve this one too, but help would be great :) Here is the next line:
m.Text = it.Name.." has been chosen! Because they bought the V.I.P room bonus!"
and here is the error:
Workspace.HideAndSeek:131: attempt to index upvalue 'it' (a nil value)
So like I said, I'll have a go at this one aswell(Like the other problems I've attempted) but help would be good. :) |
|
Jackd44Join Date: 2008-12-19 Post Count: 200 |
Oh and yeah, that code is line 131 :) |
|
|
replace the GetPlayerFromCharacter bit with game.Players[NextIt.Name] |
|
Jackd44Join Date: 2008-12-19 Post Count: 200 |
Ok, did that now I'm getting
ItNext is not a valid member of Players
Strange... |
|
YeahNickJoin Date: 2009-02-28 Post Count: 2536 |
if game.Players:FindFirstChild(NextIt.Value) then
print("OMG CART MUST BE A GENIUS")
end |
|
Jackd44Join Date: 2008-12-19 Post Count: 200 |
It's a good thing I don't just copy what people post... I read it! Muhahahaha :P |
|
|
|
Jackd44Join Date: 2008-12-19 Post Count: 200 |
Changed to value, now it says "String expected" on the same line of it = game.Players[NextIt.Value] |
|
|
Jackd44Join Date: 2008-12-19 Post Count: 200 |
Yes. |
|
|
Are you sure its value is not ""? |
|
Jackd44Join Date: 2008-12-19 Post Count: 200 |
Yes, I have a print line which prints the NextIt's name. However my roblox studio has a bug where I can't actually see values myself, put I can print it. That COULD be the cause. |
|
Jackd44Join Date: 2008-12-19 Post Count: 200 |
*but |
|
|
have you checked spelling? |
|
Jackd44Join Date: 2008-12-19 Post Count: 200 |
Ok, so I can show the value is there because this is 2 lines of the output:
Successful!
Now Player1 will be it next game!
And here is the code inside the "String setting" brick:
6-local Buyer = game.Players:playerFromCharacter(hit.Parent)
7-local NextIt = game.Workspace.ItNext
23-Buyer.leaderstats.Points.Value = Buyer.leaderstats.Points.Value - 30
24-NextIt.Value = Buyer.Character.Name
25-print("Successful!")
26-print("Now "..NextIt.Value.." will be it next game!")
So the value exists... But now I'm getting this error:
NextIt.Value is not a valid member of Players
Script "Workspace.HideAndSeek", Line 130 - global Choose_It
So it's at line 130. Here's the script near there:
129-if NextIt.Value ~= nil then
130-it = game.Players["NextIt.Value"]
131-m.Text = it.Name.." has been chosen! Because they bought the V.I.P room bonus!"
I have no idea what's going on. Please help! :/ |
|
Jackd44Join Date: 2008-12-19 Post Count: 200 |
Oh and aswell. The ["NextIt.Value"] with the speech marks don't matter, it's the same error with and without them. |
|
Jackd44Join Date: 2008-12-19 Post Count: 200 |
Have I confused everyone? :P |
|