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

Help with TweenSize() and lag issue?

Basically there is no issue with this code, everything runs. When the ammo of the weapon is changed then the gui resizes (basically a bar that shrinks according to ammo). The issue I am having is when the bar resizes it does so inwards, I only want the y axis shrinking but the x axes does too towards the top right corner (even though my argument for the tweensize has the same x value as the original???).

My other problem is a large amount of lag whenever I fire a gun, is this script the issue? Can anyone provide a different way of doing the gui that shrinks when the gun is fired?

Anyway, here's the code. Questions/tldr: What can I do to stop it shrinking towards the top right corner as a-pose to just up and down, is there a different way of doing this (reaching the same result) but easier?

player = game.Players.LocalPlayer
ammo = player:FindFirstChild("Ammo",true)
tool = script.Parent 
tool.Size = UDim2.new(0,30,0,149)


while true do
	wait()
	if ammo then
		ammo.Changed:connect(function()
			existing = script.Parent.Size
			script.Parent:TweenSize(UDim2.new(0,30,0,(ammo.Value * 4.97)), "Out", "Quad", 1)
			wait(0.2)
		end)
	end	
end

1 answer

I think the main problem with code that you were adding a bunch of events to when the ammo amount would change.

To fix this problem I recommend to just remove the while true do loop.

Updated code :

player = game.Players.LocalPlayer
ammo = player:FindFirstChild("Ammo",true)
tool = script.Parent 
tool.Size = UDim2.new(0,30,0,149)

ammo.Changed:connect(function()
	existing = script.Parent.Size
	script.Parent:TweenSize(UDim2.new(0,30,0,(ammo.Value * 4.97)), "Out", "Quad", 1, true)
end)

About the the size changing on the X Axis, I have no idea why that would be happening.

If you have any questions, concerns or just need some help with this PM me on ROBLOX!

1 comment

0

Thanks for that!

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