So the script is inside a part and when i press play i always get this error in the output if i remove FindFirstChild i then get the error attempt to index nil with 'PlayerGui' and same error with WaitForChild i cant find a way to work around it
local ss = script.Parent local player = game:GetService("Players").LocalPlayer local pGui = player:FindFirstChild("PlayerGui") --error happens here local debounce = false ss.Touched:Connect(function(tuch) if tuch and debounce == false then local pGui = game.Players.LocalPlayer:FindFirstChild("PlayerGui") local cost = tuch.Cost.Value local name = tuch.Name.Value pGui.Perks.ValueText.Text = "PRESS F TO PURCHASE COST ["..tostring(cost).."] POINTS" pGui.Perks.Enabled = true end end) ss.TouchEnded:Connect(function(tuch) pGui.Perks.Enabled = false end)
You cant get the .LocalPlayer
in script it only works in a localscript but you can get the player from the tuch
param. like this
if tuch.Parent:FindFirstChild("Humanoid") then local player = Players:GetPlayerFromCharacter(tuch.Parent) end