Hi Developers! I am pretty new to scripting so I couldn’t figure out how to reference a player in an obby I am making. I have a code with the leaderstats value “Stage”. I want to reference my player and basically say something along the lines of "if game.Players.(Player name I don’t know that I want to know how to reference even though I don’t knwo their name).leaderstats.Stage.Value = 2 then (Insert effect here) then a block will disappear blocking them from stage 2. This is how I made the leaderstats:
players.PlayerAdded:connect(function(plr)
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
stats.Parent = plr
local stage = Instance.new("IntValue")
stage.Name = "Stage"
stage.Parent = stats
local data = saveDataStore:GetAsync(plr.UserId)
if data then
print(data.Stage)
for _,stat in pairs(stats:GetChildren()) do
stat.Value = data[stat.Name]
end
else
print(plr.Name .. "has no data")
end
Is there a way I can transfer that to a local script because my script with the on PlayerAdded event is a regular script and I want only people who are on stage 2 to be able to see the effects of my code.
Yes you can something like this in a local script:
local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
local stage = leaderstats:WaitForChild("Stage")
stage.Changed:Connect(function()
if stage.Value == 2 then
-- Your Code Here
end
end)
Yes, that is what I want. I only want people who are on stage 2 or above to experience the effects. That is another question I have, how do I write the code so that people who are above stage 2 can also experience the effects?
I put the code you wrote in a local script and put the local script inside the block I want the effects to happen on and just referenced it as script.parent but it doesn’t work. Here is the code:
local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
local stage = leaderstats:WaitForChild("Stage")
stage.Changed:Connect(function()
if stage.Value == 2 then
script.Parent.Part.CanCollide = false
script.Parent.Part.Transparency = 1
script.Parent.Sign.SurfaceGui.SIGN.TextTransparency = 1
end
end)