I get this error:
Workspace.SellPlatform.SellScript:29: attempt to index a nil value
For this script:
-- When a player touches the parent object, their items will be sold for gold
local sellPart = script.Parent
-- Gives the player gold for each item they have
local function sellItems(playerItems, playerGold)
-- Gives players 100 pieces of gold for each item
local totalSell = (playerItems.Value * 100)
playerGold.Value = playerGold.Value + totalSell
playerItems.Value = 0
end
local function onTouch(partTouched)
-- Looks for a Humanoid
local character = partTouched.Parent
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
-- If a humanoid is found, gets leaderstats and calls sellItems function
if humanoid then
-- Get the player, so changes can be made to the player's leaderstats
local player = game.Players:GetPlayerFromCharacter(humanoid.Parent)
local playerStats = player:FindFirstChild("leaderstats")
local playerSpaces = playerStats:FindFirstChild("Spaces")
local playerItems = playerStats:FindFirstChild("Items")
local playerGold = playerStats:FindFirstChild("Gold")
local playerStats2 = player:FindFirstChild("Stats")
local playerSold = playerStats2:FindFirstChild("Sold")
local playerSoldRequired = playerStats2:FindFirstChild("SoldRequired")
local playerLevel = playerStats2:FindFirstChild("Level")
local playerLevelGui = player.PlayerGui:FindFirstChild("Stats").Level
-- Sells Items and then changes the player's spaces and money
playerSold.Value = playerSold.Value + playerItems.Value
sellItems(playerItems, playerGold)
if playerSold.Value >= playerSoldRequired.Value and playerSpaces.Value >= playerItems.Value then
playerLevel.Value = playerLevel.Value + 1
playerLevelGui.Visible = true
playerSoldRequired.Value = playerLevel.Value * 100 + playerSoldRequired.Value
playerSold.Value = 0
end
end
end
sellPart.Touched:Connect(onTouch)

28 comments
Yeah, It appears in PlayerGui, but idk...how can i move them there using a script?
Yes..But this "index nil value" kills me..
Stats is not a valid member of PlayerGui
Stats is not a valid member of PlayerGui. I think using StarterGui instead makes it visible to everyone, and i only want the localplayer to see the Gui when he meets the requirement.
Ignore the "Stats is not a valid member of PlayerGui." from above.
AradIsHere, please stop spreading misinformation.
This is the starterGui : http://prntscr.com/ml3nke
The frame doesn't turn visible... I tried with "local playerLevelGui = game.StarterGui.Stats.Level" and then "playerLevelGui.Visible = true"
It should not have worked for you. That code is just modifying what replicates to clients when they die or join. Now stop spreading misinformation like I asked, AradIsHere.
thats why i dont post answers...
Why'd you remove your comments? Even if they were wrong, they were important for context.
ady1111, I'll help you out. Is the line the error occurs on the same line as line twenty-nine in the script you posted? If not, please tell me the line that is erroring.
Yes, line 29 is the problem
Ok, for debugging purposes, I'd like you to, before the line that's erroring, write: print(player); print(player.PlayerGui); print(player.PlayerGui:FindFirstChild("Stats"))
Tell me if one of the above prints nil.
1.ady1111 2.PlayerGui 3.nil
Ok, FindFirstChild returns nil when an item with the name matching the string passed as the argument is not found.
This is the PlayerGui: http://prntscr.com/ml41dx
Right, and that confuses me because this should only be erroring if FindFirstChild returns nil, but FindFirstChild shouldn't be returning nil. Do you mind commenting out that line and telling me what happens?
What do you mean?
Basically, what happens when you remove that line of code?
Workspace.SellPlatform.SellScript:36: attempt to index global 'playerLevelGui' (a nil value)
Ok, now we know for sure that the FindFirstChild returning nil is causing the issue.
I did some research, and, apparently, the server can't access things in the PlayerGui. You're going to have to modify that gui locally.
Remote events are your only option in this scenario.
So how should i do it? If the line 34 condition is met, the gui becomes visible...don't know how...I always have trouble with this error.
Managed to do it with Remote Events, thank you!
Items in
StarterGuiare cloned locally, so you'll have to use remotes to be able to accomplish what you're trying to do.