Workspace with nil on :WaitForChild

Hello, so Im trying to make a sell and this is what happens:

Script:
Script3

You defined player as a local variable inside of the if h then statement which ends on the following line. Because of this, that variable can only be accessed within that condition because of how variable scope works.

To resolve this, you can move the end right below the line that says Selling.Value = 0.

However, I would suggest removing the Humanoid check anyway since you could just check if it’s a player when the function begins.

There is no Player variable so it doesn’t know what the player is you will have to do

local player = game.Players.LocalPlayer

Put that at the start and it should work.

I will try to see if it works.

Still saying the same message in the output

@pocvq and @StrongBigeMan9 I tried and still the same message in the output. Could it be because I don’t have HTTPS on or because the game is not published yet?

I don’t think that would effect it as I used that in a game not released or published to
Edit: obviously not the exact same I made my own

What does the codeblock look like now? HTTPS is completely unrelated and is not required for that function to work properly.

Here’s an example of what the codeblock could be modified to

local Players = game:GetService("Players")
local part = script.Parent

part.Touched:Connect(function(hit)
    local player = Players:GetPlayerFromCharacter(hit.Parent)

    if player then
        -- Reference leaderstats and continue with rest of the function
    end
end)

OOF
Now its saying Money is nil

I might not be able to fix it. I might have to use a free model.

Could you please show what the updated codeblock looks like now? No need to use a free model – it’s better that we troubleshoot it and learn these to improve.

new script3

local part = script.Parent
part.Touched:Connect(function(hit)
	local h = hit.Parent:FindFirstChild("Humanoid")
	if h then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		local leaderstats = player:WaitForChild("leaderstats")
		local money = leaderstats.Cash
		local Selling = leaderstats.Strength
		if Selling.Value >= 0 then
		money.Value += Selling.Value * 1
			Selling.Value = 0
		end	
	end
end)	

You put the end statement after defining player, then after that you put the leaderstats variable and it didn’t find leaderstats because player is now nil because you ended/closed the part of the script where the player variable is

Sorry to everyone that was helping me. @DevCramp fixed it. Thank you for the help tho.

I just did it. It is now fixed.

Also there is no close post button.