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