Attempting to check if string value exists in Character's new instance folder

I am implementing a character status system in a project I’m doing, in this case, I am trying to check if the client’s ‘PlayerStatusPositive’ folder (A new instance created by a modulescript when a player’s character is added) has a particular child ‘SprintStatus’ and if not it replicates the string value from a server storage folder to the client’s folder. However, when I try to check if the client’s child (‘SprintStatus’) exists or not, I am given an error:

Note: I have tried using IV pairs and tables, however came to no solution.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Debris = game:GetService("Debris")
local SprintRemote = ReplicatedStorage.Remotes.PlayerActions:WaitForChild("SprintRemote")
local Players = game:GetService("Players")
local PlayerStatuses = game:GetService("ServerStorage"):WaitForChild("PlayerStatuses")
local PlayerStatusManager = require(game:GetService("ServerScriptService").PlayerActions:FindFirstChild("PlayerStatusManager"))
local PlayerStatusPositive = PlayerStatusManager.PlayerStatusPositive

SprintRemote.OnServerEvent:Connect(function(Player) -- Fires when client sends message to server
	local Character = Player.Character or Player.CharacterAdded:Wait()
	
	if Character then
		local Humanoid = Character:FindFirstChildOfClass("Humanoid")
		
		if Humanoid then -- Checks if player has humanoid before toggling walkspeed change
			
			if Humanoid.WalkSpeed < 23 then -- Sees if player is not sprinting
				Humanoid.WalkSpeed = 23 -- CHANGES WALKSPEED
				
				if PlayerStatusPositive:FindFirstChild("SprintStatus") == nil then
					local Sprinting = PlayerStatuses:WaitForChild("SprintStatus"):Clone() -- Adds Sprint status value to player
					Sprinting.Parent = PlayerStatusManager.PlayerStatusPositive
				end
				
			elseif Humanoid.WalkSpeed >= 23 then -- Sees if player is sprinting
				Humanoid.WalkSpeed = 16 -- CHANGES WALKSPEED
				
				if PlayerStatusPositive:FindFirstChild("SprintStatus") then
					Debris:AddItem(PlayerStatusPositive:FindFirstChild("SprintStatus"), 0) -- Removes Sprint status value to player
				end
				
			end
			
		end
	end
end)

Additional: Modulescript

local PlayerStatusManager = {}

game:GetService("Players").PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		PlayerStatusManager.PlayerStatusNegative = Instance.new("Folder")
		PlayerStatusManager.PlayerStatusNegative.Name = "PlayerStatusNegative"
		PlayerStatusManager.PlayerStatusNegative.Parent = Character
		
		PlayerStatusManager.PlayerStatusPositive = Instance.new("Folder")
		PlayerStatusManager.PlayerStatusPositive.Name = "PlayerStatusPositive"
		PlayerStatusManager.PlayerStatusPositive.Parent = Character
	end)
end)

return PlayerStatusManager
local PlayerStatusPositive = PlayerStatusManager.PlayerStatusPositive

I’m geniunly confused what you’re trying to do with this?

You shouldn’t make those variables for the module itself,

		local folderNegative = Instance.new("Folder")
		folderNegative.Name = "PlayerStatusNegative"
		folderNegative.Parent = Character
		
		local folderPositive = Instance.new("Folder")
		folderPositive.Name = "PlayerStatusPositive"
		folderPositive.Parent = Character

change that module information to something like this ^

Instead of doing; “PlayerStatusPositive:FindFirstChild(“SprintStatus”)” now to index it, do this instead; “local PlayerStatusPositive = Character:FindFirstChild(“PlayerStatusPositive”)”

And so on

I just realized that there’s no point in declaring those variables as the module script’s or accessing them through there since either way they’re gonna be referred to through the client’s children through the character in-game. I’ll be sure to check if that changes anything and I’ll update you.

Thank you,

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.