Workspace.KeyboardActivator.Script:5: attempt to index nil with 'WaitForChild'
local touch = script.Parent
local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
local Money = leaderstats:WaitForChild("Cash")
if Money.Value > 30 then
touch.Touched:Connect(function()
for i,part in pairs(game.Workspace.Keyboard:GetChildren()) do
part.Transparency = 0
part.CanCollide = true
end
touch.Transparency = 1
touch.Highlight.Enabled = false
touch.PointLight.Enabled = false
touch.BillboardGui.Enabled = false
touch.Sound:Play()
touch.CanTouch = false
end)
else
print("Player has no more money to purchase Keyboard")
end
Im really stuck because right now im just tring to get it so that if you touch the part, and you dont have enough money, it just says âu dont have moneyâ and not run that function. but incase the player does have enough money, it does
idk if im doing anything wrong but its not working. here is my new script
local touch = script.Parent
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
local Money = leaderstats:WaitForChild("Cash")
touch.Touched:Connect(function(hit)
local plr = game:GetService('Players'):GetPlayerFromCharacter(hit.Parent)
if plr then
local Money = plr.leaderstats.Cash
if Money and Money.Value >= 30 then
for i,part in pairs(game.Workspace.Keyboard:GetChildren()) do
part.Transparency = 0
part.CanCollide = true
end
touch.Transparency = 1
touch.Highlight.Enabled = false
touch.PointLight.Enabled = false
touch.BillboardGui.Enabled = false
touch.Sound:Play()
touch.CanTouch = false
end
end
end)
I was scripting in the website so there may have been some error, this is my fix in studio:
local touch = script.Parent
touch.Touched:Connect(function(hit)
local plr = game:GetService('Players'):GetPlayerFromCharacter(hit.Parent)
if plr then
local Money = plr.leaderstats.Cash
if Money and Money.Value >= 30 then
for i,part in pairs(game.Workspace.Keyboard:GetChildren()) do
part.Transparency = 0
part.CanCollide = true
end
touch.Transparency = 1
touch.Highlight.Enabled = false
touch.PointLight.Enabled = false
touch.BillboardGui.Enabled = false
touch.Sound:Play()
touch.CanTouch = false
end
end
end)