How to Clone a Value into Player?

Hello!
I have a problem. Obvious, else I wouldn’t be here.
I would like to clone a Value that I have stored as a Child from the Script into the Player.
The code I’ve tried using is below:

local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
	local OxygenValue = script.OxygenLeft
	OxygenValue:Clone().Parent = player
end)

I can’t tell what’s wrong with this? I’m not so advanced in ServerSide Scripting, so a quick look over and tell me what’s wrong would be amazing. The script is in ReplicatedStorage.

Thanks!

1 Like

Your script seems to be working just fine.

Also, you should store your server-scripts in ServerScriptService in this case.
More information here: ReplicatedStorage | Roblox Creator Documentation

Huh, it doen’t work when I put it in ReplicatedStorage, but it does in ServerScriptService! Great, thank you.

That’s because server-scripts don’t run in ReplicatedStorage.

Like Xacima said, scripts placed within ReplicatedStorage don’t automatically run. If you want to create scripts that automatically run when the server starts, place them within ServerScriptService - thats what its designed for.

Usually you leave ReplicatedStorage as a sort of storage container for ModuleScripts, RemoteFunctions, and RemoteEvents.