How to make model scale depending on leaderstat value like my pet rock

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)`

image

Hello,

This is a great idea you have here.

I have the following in mind which might help you

OPTION 1

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.

sorry i meant starter pack bla blah

1 Like

Can you try changing the script to local script?

that wouldnt work it already gets the player and model and making it local would only change the size for you if it does work

Is there any way to publish this tool so I can review it on my end to give you a proper solution?

tool.rbxm (15.5 KB)

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

image

1 Like

thanks only issue is that it doesnt grow outwards and it clips through the floor
image

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.