Hi, me again... every time one of you wonderful people help me I get a little bit closer to not being useless.
My next issue is with a leaderboard script I found that worked but always gave me the following output:
Torso is not a valid member of Model
Here is the script (updated to replace Torso with HumanoidRootPart as per my reading on the subject of Torso not being a recognised part of the model):
function onArrival(object) local player = game.Players:playerFromCharacter(object) if player ~= nil then local leaderstats = player.leaderstats local setlevel = game.Workspace:FindFirstChild(leaderstats.Stage.Value) print("gah") object.HumanoidRootPart.CFrame = object.HumanoidRootPart.CFrame + Vector3.new(0,3,0) wait() object.HumanoidRootPart.CFrame = setlevel.CFrame + Vector3.new(0,3,0) end end function setupBoard(object) if object.className == "Player" then local addls = Instance.new("IntValue") addls.Name = "leaderstats" local addstage = Instance.new("IntValue") addstage.Name = "Stage" addstage.Value = 0 addstage.Parent = addls addls.Parent = object end end game.Players.PlayerAdded:Connect(setupBoard) game.Workspace.PlayerAdded:Connect(onArrival)
However, now I get this error:
Workspace.Leaderboard:9: attempt to index local 'sl' (a nil value)
If HumanoidRootPart is a valid part of my character I'm not sure why it is breaking the sl variable... any guidance would be great.
Thanks
[edit] During the course of this I found that the above code was outdated and basically broken for my needs... the following is the current working model I'm using:
local datastore = game:GetService("DataStoreService") local ds1 = datastore:GetDataStore("GemSaveSystem") game.Players.PlayerAdded:connect(function(plr) local folder = Instance.new("Folder", plr) folder.Name = "leaderstats" local stage = Instance.new("IntValue", folder) stage.Name = "Stage" stage.Value = ds1:GetAsync(plr.UserId) or 1 ds1:SetAsync(plr.UserId, stage.Value) stage.Changed:connect(function() ds1:SetAsync(plr.UserId, stage.Value) end) end)
Not sure if it'll help but you can't do
game.Workspace.PlayerAdded
Players aren't added to the workspace, do ChildAdded then check for the child's name in Players.
Thanks to the guidance of Phlegethon5778, I've done my best to tidy the code up a bit and updated some of the outdated methods etc (I've edited the OP to include the new code... still won't be perfect, as stated, I'm new to this!). The leaderboard still works but now the only error I get is:
PlayerAdded is not a valid member of Workspace
from line 26... could it be firing before the Player has been added to the Workspace?