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)

2 comments
Please properly indent your code, use proper events (for instance PlayerAdded as opposed to ChildAdded), use function/variable names that make sense, and use non-deprected methods (for instance, :Connect instead of :connect).
Apologies, I'll try to do that. As stated I'm still very new to this and this is code that I've 'inherited' rather than written. Those few pointers alone may help explain why updating the code for R15 has not worked, I still need help overall but will look to address the pointers you have listed in the meantime