Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i change the size of a tool?

im starting to finish my simulator game so i tried making it so the weight will change size with the player's strength. there are no errors but it deletes datastore and doesnt change size. can somone help?

local serverStorage = game:GetService("ServerStorage")
local datastore = game:GetService("DataStoreService"):GetDataStore("PlayerSave3")

game.Players.PlayerAdded:Connect(function(player)
		
		
		local leaderstats = Instance.new("Folder")
		leaderstats.Name = "leaderstats"
		leaderstats.Parent = player
		
		local strength = Instance.new("NumberValue")
		strength.Name = "Strength"
		strength.Parent = leaderstats
		
		local rebirths = Instance.new("IntValue")
		rebirths.Name = "Rebirths"
		rebirths.Parent = leaderstats
		
		local dataFolder = Instance.new("Folder")
		dataFolder.Name = player.Name
		dataFolder.Parent = serverStorage.RemoteData
		
		local debounce = Instance.new("BoolValue")
		debounce.Name = "Debounce"
		debounce.Parent = dataFolder
		
		local strengthdata, rebirthdata
		
		local success, errormessage = pcall(function()
			strengthdata = datastore:GetAsync("strength-"..player.UserId)
			rebirthdata = datastore:GetAsync("rebirths-"..player.UserId)
		end)
		
		if success then
			if strengthdata then
				strength.Value = strengthdata
				rebirths.Value = rebirthdata
			end
		end

player.CharacterAppearanceLoaded:Connect(function(character)
	local humid = character.Humanoid
	humid:WaitForChild("BodyDepthScale").Value = .5 + (strength.Value / 250)
	humid:WaitForChild("BodyHeightScale").Value = .5 + (strength.Value / 250)
	humid:WaitForChild("BodyWidthScale").Value = .5 + (strength.Value / 250)
	humid:WaitForChild("HeadScale").Value = .5 + (strength.Value / 250)
	humid.WalkSpeed = 16 + (strength.Value / 250)
	strength:GetPropertyChangedSignal("Value"):Connect(function()
		humid:WaitForChild("BodyDepthScale").Value = .5 + (strength.Value / 250)
		humid:WaitForChild("BodyHeightScale").Value = .5 + (strength.Value / 250)
		humid:WaitForChild("BodyWidthScale").Value = .5 + (strength.Value / 250)
		humid:WaitForChild("HeadScale").Value = .5 + (strength.Value / 250)
		humid.WalkSpeed = 16 + (strength.Value / 250)
		game.StarterPack:WaitForChild("Weight").Size.Value = .5 + (strength.Value / 250) -- this is where it wont work
		end)
	end)
end)

game.Players.PlayerRemoving:Connect(function(player)
	 local success, errormessage = pcall(function()
		datastore:SetAsync("strength-"..player.UserId,player.leaderstats.Strength.Value)
		datastore:SetAsync("rebirths-"..player.UserId,player.leaderstats.Rebirths.Value)
	end)
end)

5 comments

0

Which line is the "infinite yield possible" found on? If there are infinite yields then it shows you where the problem is occurring

0

Is the "Size" the Size Property of a Part or an Int/NumValue ?

0

idk

0

Try now, i made a slight adjustment

0

responding to your comment, ah ok, so the tool has a handle named "Handle" in it that is supposed to change size i suppose?

1 answer

✓ Accepted answer

Improvements

Use GetService() for the Players and StarterPack Services

Use Local Variables for items that are used more than once in your code

Use a Table to store your data rather than different prefixes or datastores

Quick Fix

On Line 54, you are changing the value of the tool in the StarterPack, not the player's Backpack, in order to do this, you'd simply change the line to

local sizer = .5 + (strength.Value / 250)
player:WaitForChild("Backpack"):WaitForChild("Weight")::WaitForChild("Handle").Size = Vector3.new(sizer, sizer, sizer)

Revised Server Script

local serverStorage = game:GetService("ServerStorage")
local datastore = game:GetService("DataStoreService"):GetDataStore("PlayerSave3")

game:GetService("Players").PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local strength = Instance.new("NumberValue")
	strength.Name = "Strength"
	strength.Value = 0
	strength.Parent = leaderstats

	local rebirths = Instance.new("IntValue")
	rebirths.Name = "Rebirths"
	rebirths.Value = 0
	rebirths.Parent = leaderstats

	local dataFolder = Instance.new("Folder")
	dataFolder.Name = player.Name
	dataFolder.Parent = serverStorage:WaitForChild("RemoteData")

	local debounce = Instance.new("BoolValue")
	debounce.Name = "Debounce"
	debounce.Parent = dataFolder

	local success, errormessage = pcall(function()
		datastore:GetAsync(player.UserId)
	end)

	if success then
		local LoadArray = datastore:GetAsync(player.UserId)
		if LoadArray then
			strength.Value = LoadArray[strength.Name]
			rebirths.Value = LoadArray[rebirths.Name]
		end
	else
		warn(errormessage)
	end

	player.CharacterAppearanceLoaded:Connect(function(character)
		local humid = character:WaitForChild("Humanoid")
		local bds = humid:WaitForChild("BodyDepthScale")
		local bhs = humid:WaitForChild("BodyHeightScale")
		local bws = humid:WaitForChild("BodyWidthScale")
		local hhs = humid:WaitForChild("HeadScale")
		local pbw = player:WaitForChild("Backpack"):WaitForChild("Weight"):WaitForChild("Handle")
		
		local default1 = 0.5
		local default2 = 16
		local base = 250
		
		local p1 = default1 + (strength.Value / base)
		local s1 = default2 + (strength.Value / base)
		
		bds.Value = p1
		bhs.Value = p1
		bws.Value = p1
		hhs.Value = p1
		humid.WalkSpeed = s1
	
		strength:GetPropertyChangedSignal("Value"):Connect(function()
			local p2 = default1 + (strength.Value / base)
			local s2 = default2 + (strength.Value / base)
			
			bds.Value = p2
			bhs.Value = p2
			bws.Value = p2
			hhs.Value = p2
			pbw.Size = Vector3.new(p2, p2, p2)
			humid.WalkSpeed = s2
		end)
	end)
end)

game:GetService("Players").PlayerRemoving:Connect(function(player)
	local lead = player:WaitForChild("leaderstats")
	local str = lead:WaitForChild("Strength")
	local reb = lead:WaitForChild("Rebirths")
	
	local SaveArray = {}
	SaveArray[str.Name] = str.Value
	SaveArray[reb.Name] = reb.Value

	local success, errormessage = pcall(function()
		datastore:SetAsync(player.UserId, SaveArray)
	end)
	
	if not success then
		warn(errormessage)
	end
end)

6 comments

0

can you edit? on the script it says infinite yield possible and deletes the current data store. it also doesnt change thesize of the weight P.S i think the deleting of datastore is normal

0

infinite yield on line 47 its when "WaitForChild("Size")"

0

Infinite yield possible on 'Players.AlbertoMiAmigo2.Backpack.Weight:WaitForChild("Size")'

0

you said you made a minor adjustment it seems fine but it says Script 'ServerScriptService.Stats', Line 70 " Size is not a valid member of Tool"

0

thanks it works i did what you said "handle.size" but now the data wont save if you could fix that i will accept thank you for your help tho

0

wait i made a other game to test this when i make big changes so i think its because i didnt enable API services

This discussion is preserved as it was. New answers, comments, and votes are closed.