Hello. I am wanting to make it so that a model is scaled depending on how big or small the leaderstat is. The default size would be 0.3 and it would go higher the more your leaderstat is like the game my pet rock. I have tried some stuff but its not working:
game.Players.PlayerAdded:Connect(function(player)
local leaderstat = player.leaderstats.Time
local model = script.Parent
local function updateScale()
model:ScaleTo(0.3 + leaderstat.Value)
end
leaderstat.Changed:Connect(updateScale)
end)`
game.Players.PlayerAdded:Connect(function(player)
local leaderstat = player.leaderstats.Time
local model = script.Parent
local DefaultScale = 0.3
local function updateScale()
local ValueToAdd = leaderstat.Value / 100
if DefaultScale + ValueToAdd <= 1 then
model:ScaleTo(DefaultScale + ValueToAdd)
end
end
leaderstat.Changed:Connect(updateScale)
end)
OPTION 2
game.Players.PlayerAdded:Connect(function(player)
local leaderstat = player.leaderstats.Time
local model = script.Parent
local DefaultScale = 0.3
local function updateScale()
local ValueToAdd = leaderstat.Value / 1000
if DefaultScale + ValueToAdd <= 1 then
model:ScaleTo(DefaultScale + ValueToAdd)
end
end
leaderstat.Changed:Connect(updateScale)
end)
Thanks for the scripts, However they dont work. To make it clear this is a server script under a model under a part called handle under a tool under starterpack. Also, the scripts you provided are the same, did you mean to do this.
The cause of your issue was PlayerAdded, which wouldn’t be detecting players who were joining.
Instead, you could write the script like this, and it would work:
local players = game:GetService("Players")
local player = script:FindFirstAncestorWhichIsA("Player") or players:GetPlayerFromCharacter(script.Parent.Parent.Parent)
local leaderstats = player:WaitForChild("leaderstats")
local leaderstat = leaderstats:WaitForChild("Time")
local model = script.Parent
local function updateScale()
model:ScaleTo(0.3 + leaderstat.Value)
end