Sprites are moving when they shouldn't?
(Yes, I'm making a sprite-based game. Don't ask why.)
01 | local label = script.Parent |
02 | local RunService = game:GetService( "RunService" ) |
03 | local Debris = game:GetService( "Debris" ) |
04 | local length = label:WaitForChild( "Length" ) |
05 | local width = label:WaitForChild( "Width" ) |
06 | local angle = label:WaitForChild( "Angle" ) |
07 | local delaytime = label:WaitForChild( "Delay" ) |
08 | local life = label:WaitForChild( "Lifetime" ) |
09 | local t = label:WaitForChild( "Transparency" ) |
11 | local delayLine = Instance.new( "Frame" ) |
12 | delayLine.Parent = label |
13 | delayLine.Name = "DelayLine" |
14 | delayLine.Size = UDim 2. new( 0 , 1 , length.Value, 0 ) |
15 | delayLine.AnchorPoint = Vector 2. new( 0 , 0 ) |
16 | delayLine.BorderSizePixel = 0 |
17 | delayLine.BackgroundColor 3 = Color 3. fromRGB( 255 , 255 , 255 ) |
18 | delayLine.BackgroundTransparency = 0.5 |
19 | delayLine.Position = UDim 2. new( 0 , 0 , 0 , 0 ) |
21 | local hitbox = Instance.new( "Frame" ) |
23 | hitbox.AnchorPoint = Vector 2. new( 0.5 , 0.5 ) |
24 | hitbox.Size = UDim 2. new( 0.33 , 0 , 1 , 0 ) |
25 | hitbox.Position = UDim 2. new( 0.5 , 0 , 0.5 , 0 ) |
26 | hitbox.BackgroundTransparency = 1 |
28 | local hitboxScript = game.ReplicatedStorage.BulletScripts:WaitForChild( "LinearHitboxScript" ):Clone() |
29 | hitboxScript.Parent = hitbox |
30 | hitboxScript.Disabled = true |
32 | delay(delaytime.Value, function () |
33 | label:TweenSize(UDim 2. new( 0 , width.Value, 0 , length.Value), "Out" , "Quad" , 0.25 , false , function () |
34 | Debris:AddItem(label, life.Value) |
38 | function getRealAngle(a) |
39 | local val = math.abs(a - 180 ) |
48 | label:GetPropertyChangedSignal( "Size" ):Connect( function () |
49 | if label.Size = = UDim 2. new( 0 , 1 , 0 , 1 ) then |
50 | delayLine.Visible = true |
51 | label.ImageTransparency = 1 |
52 | hitboxScript.Disabled = true |
54 | delayLine.Visible = false |
55 | label.ImageTransparency = t.Value |
56 | hitboxScript.Disabled = false |
60 | RunService.RenderStepped:Connect( function () |
61 | label.Rotation = getRealAngle(angle.Value) |
When the sprite is created, its size is set to UDim2.new(0, 1, 0, 1)
. After a certain amount of time passes, the sprite expands to its true size, determined by the values of Length
and Width
.
However, when the sprite's size changes, it moves towards the bottom of the screen, even though I don't have anything that changes the position in the script. Is there a way to fix it?
Here's the function that creates these sprites, in case it helps with figuring out the problem:
01 | function lib:CreateStraightLaser(x, y, angle, length, width, delaytime, graphic, timer) |
02 | local RealLaser = getShotData(graphic) |
03 | local BoundBox = RealLaser.Bound |
04 | local sLaserScript = ExtraScriptsDirectory:WaitForChild( "StraightLaserScript" ) |
06 | local sLaser = Instance.new( "ImageLabel" ) |
07 | sLaser.Name = RealLaser.Name |
08 | sLaser.Position = UDim 2. new( 0 , x, 0 , y) |
09 | sLaser.Size = UDim 2. new( 0 , 1 , 0 , 1 ) |
10 | sLaser.AnchorPoint = Vector 2. new( 0.5 , 0 ) |
11 | sLaser.BackgroundTransparency = 1 |
12 | sLaser.Image = ShotSheetImage |
13 | sLaser.ImageRectOffset = BoundBox.Min |
14 | sLaser.ImageRectSize = Vector 2. new(BoundBox.Width, BoundBox.Height) |
15 | sLaser.ImageTransparency = 1 |
17 | local l = Instance.new( "NumberValue" ) |
22 | local a = Instance.new( "NumberValue" ) |
27 | local w = Instance.new( "NumberValue" ) |
32 | local d = Instance.new( "NumberValue" ) |
37 | local life = Instance.new( "NumberValue" ) |
39 | life.Name = "Lifetime" |
42 | local t = Instance.new( "NumberValue" ) |
44 | t.Name = "Transparency" |
45 | t.Value = RealLaser.Transparency |
47 | local newLaserScript = sLaserScript:Clone() |
48 | newLaserScript.Parent = sLaser |
49 | newLaserScript.Disabled = false |
51 | sLaser.Parent = getLocalPlayerGui() |