Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does trying to access .PlayerScripts from my player always results in an error?

When trying to access playerWhoActivated.Playerscripts, it returns the error PlayerScripts is not a valid member of Player "Players.brandons2005"

I included my whole script, but the important lines are 10, which correctly prints my player directory as "brandons2005" every time, and line 11, which always fails to find PlayerScripts from brandons2005

Everything else in this script works, and it only broke after I tried to implement a Debounce located as a bool value in Playerscripts.

I don't believe it's a loading error, since I've waited 10 seconds before pressing the proximity prompt and it still returns the same error

local ReplicatedFirst = game.ReplicatedFirst
local globalVariables = require(game.ReplicatedFirst.GlobalVariables)
local inventorySort = require(game.ReplicatedStorage.InventorySort)
local ReplicatedStorage = game.ReplicatedStorage
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local suppliesContainer = script.Parent

local function startSuppliesTimer(timeLeft, PlayerTorso, PlayerGui, supplies, playerWhoActivated)
	print(playerWhoActivated)
	local debounce = playerWhoActivated.PlayerScripts.Debounce
if debounce.Value ~= true then	
	local label = playerWhoActivated.PlayerGui.SuppliesGainGUI.SuppliesGainLabel
	local delayEvent = Instance.new("BindableEvent")
		debounce.Value = true
	local connection
	connection = RunService.Heartbeat:Connect(function(step)
		print(connection)
		print(timeLeft)
		timeLeft -= step
		local seconds = math.floor(timeLeft % 60)
		label.Text = string.format("i", seconds)
		print(label.Text)
		local distance = (suppliesContainer.Position - PlayerTorso.Position).Magnitude
		print(distance)
		if distance > 15 then
			delayEvent:Fire()
			connection:disconnect()
			PlayerGui.SuppliesGainGUI.Enabled = false
			debounce.Value = false
		end
		if timeLeft <= 0 then
			delayEvent:Fire()
			connection:disconnect()
			while globalVariables.squareProgress ~= 0 do
				globalVariables.squareProgress = 0

			end
			label.Text = "Supplies Gathered!"
			local sound = Instance.new("Sound", game.Workspace)
			sound.SoundId = "rbxassetid://9120129807"
			sound.PlayOnRemove=true
			sound.Volume = 3
			sound:Play()
			if supplies then
				supplies.Value = supplies.Value + 1
				inventorySort.SortInventory(playerWhoActivated)
				debounce.Value = false
			end
			wait(1)
			PlayerGui.SuppliesGainGUI.Enabled = false
		end
			delayEvent.Event:Wait()
	end)
	end
end
	
	

workspace.SuppliesContainer.ProximityPrompt.Triggered:Connect(function(playerWhoActivated)
	local humanoid = playerWhoActivated.Character:FindFirstChildWhichIsA("Humanoid")
	print(humanoid)
	if humanoid then
		local PlayerGui = playerWhoActivated.PlayerGui
		-- Update the player's leaderboard stat
		local leaderstats = playerWhoActivated.leaderstats
		local supplies = leaderstats and leaderstats:FindFirstChild("Supplies")
		local PlayerTorso = playerWhoActivated.Character.UpperTorso
		print("should start")
		PlayerGui.SuppliesGainGUI.Enabled = true
		startSuppliesTimer(3, PlayerTorso, PlayerGui, supplies, playerWhoActivated)
	end
end)

1 answer

Nvm should have looked it up first and not have assumed I did it wrong. Regular scripts can't access PlayerScripts, I put Debounce in PlayerGuis and it now works perfectly fine

This discussion is preserved as it was. New answers, comments, and votes are closed.