Why am I getting this error?

I’m trying to create a simple remote event but when I try to set a value inside the remote event function it keeps saying that the folder the value is in (or the value itself) isn’t there.

image

Remote Event Code:

local RemoteEvent = game.ReplicatedStorage:WaitForChild("setPlayingToFalse")
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer

RemoteEvent.OnClientEvent:Connect(function()
	localPlayer.values.playing.Value = false
	print("set to false")
end)

Value Creation Code:

game.Players.PlayerAdded:Connect(function(player)
	
	local values = Instance.new("Folder", player)
	values.Name = "values"
	
	local playerPlaying = Instance.new('BoolValue', player)
	playerPlaying.Name = "playing"
	playerPlaying.Value = false
	
	playerPlaying.Parent = player.values

end
4 Likes

Try this:

game.Players.PlayerAdded:Connect(function(player)
	local values = Instance.new("Folder")
	values.Name = "values"
    values.Parent = player
	
	local playerPlaying = Instance.new('BoolValue')
	playerPlaying.Name = "playing"
	playerPlaying.Value = false
    playerPlayer.Parent = values
end

And on the client do:

local RemoteEvent = game.ReplicatedStorage:WaitForChild("setPlayingToFalse")
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer

RemoteEvent.OnClientEvent:Connect(function()
	localPlayer:WaitForChild("values"):WaitForChild("playing").Value = false
	print("set to false")
end)

Notes:
On the values creation script:
1.do not put the parent inside the instance.new(), it’s been explained multiple times that it’s better to parent it after you’ve assigned all the properties you needed.
2.You parented playerPlayer to player.values where you could’ve simply just parented it directly to values you’ve created above.

On the client side:
Sometimes it might take time to get the leaderstats or in your case, the values folder, so you’ll need to use WaitForChild() method to make sure you won’t infinite yield to find values

3 Likes

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