So its a tycoon. and this is the collector brick that removes the block and gives you money
01 | ``script.Parent.Touched:connect( function (hit) |
02 | local N = script.Parent.Parent.Parent.Owner.Value |
03 | local P = game.Players:GetPlayerFromCharacter(N) |
04 | if P:FindFirstChild( "leaderstats" ) ~ = nil then |
05 | local Mon = P.leaderstats.Cash.Value |
06 | if hit.Name = = "Tril" then |
07 | Mon = Mon + 10 |
08 | elseif hit.Name = = "TriU" then |
09 | Mon = Mon + 20 |
10 | end |
11 | else |
12 | print ( "Leaderstats is not there." ) |
13 |
14 | end |
15 | end ) |
16 | `` |
but it keeps giving me this error: Unable to cast value to Object
and i have a StringValue 3Parents up that contains the players name when he buys the tycoon.
Try this:
01 | script.Parent.Touched:connect( function (hit) |
02 | local N = script.Parent.Parent.Parent.Owner.Value |
03 | local P = game.Players:FindFirstChild(N) --Changed this line |
04 | if P:FindFirstChild( "leaderstats" ) ~ = nil then |
05 | local Mon = P.leaderstats.Cash.Value |
06 | if hit.Name = = "Tril" then |
07 | Mon = Mon + 10 |
08 | elseif hit.Name = = "TriU" then |
09 | Mon = Mon + 20 |
10 | end |
11 | else |
12 | print ( "Leaderstats is not there." ) |
13 | end |
14 | end ) |
The problem was that you were trying to define the player as a string, which you can't do. You need to have the script search through the players with the string, and connect it to the Players name. Anyways, I believe this should work now. If you have any further problems or questions, please leave a comment below. Hope I helped :P