Images are not visible and random position broken

Ok, my problem is that some of the images are not visible in the screen even when the visible property is true and the ImageTransparency property is 0, the textlabel has the same problem too, i modify this properties on the script but idk what is going on, and i want to make the image and textlabel appears on the screen with a random position on the frame but this works only once, when i click again appears in the same position without changing. I dont know if its a studio problem and sorry for my English.

Local Script
--[Important Variables]
local RS = game:GetService("ReplicatedStorage")
local TS = game:GetService("TweenService")
local GainStrengthEvent = RS.RemoteEvents.GainStrength
local player = game.Players.LocalPlayer
local WeightTool = script.Parent
local db = false
--[Animation Variables]
local StrengthAnimationEquip = script.Parent:WaitForChild("StrengthAnimationEquip", 0.5)
local StrengthAnimationActivate = script.Parent:WaitForChild("StrengthAnimationActivate", 0.5)
local AnimationTrackEquip
local AnimationTrackActivate
local humanoid
--[Gui Variables]
local StarterGui = game:GetService("StarterGui")
local GainStrengthGui = StarterGui.GainStrengthGui
local StrengthImage = GainStrengthGui.StrengthLabel.StrengthFrame.StrengthImageLabel
local StrengthLabel = StrengthImage.Parent.StrengthLabel
local StrenghtLabelStroke = StrengthLabel.UIStroke

local Tweeninfo = TweenInfo.new(1, Enum.EasingStyle.Back, Enum.EasingDirection.Out, 0, false, 0)
local ImagePosition = UDim2.fromOffset(math.random(25, 572), math.random(25, 368))
local ImageLabelPosition = UDim2.fromOffset(ImagePosition.X.Offset + 20, ImagePosition.Y.Offset - 20)

local Tween = TS:Create(StrengthImage, Tweeninfo, {Position = ImagePosition})
local TweenLabel = TS:Create(StrengthLabel, Tweeninfo, {Position = ImageLabelPosition})

local Tweeninfo2 = TweenInfo.new(2, Enum.EasingStyle.Back, Enum.EasingDirection.Out, 0, false, 0)
local ImageRotation = 360

local Tween2 = TS:Create(StrengthImage, Tweeninfo2, {Rotation = ImageRotation})

local Tweeninfo3 = TweenInfo.new(1.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 1)
local LabelSize = UDim2.new(0.15, 0, 0.1, 0)

local Tween3 = TS:Create(StrengthLabel, Tweeninfo3, {Size = LabelSize})

local Tweeninfo4 = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, true, 0)
local ImageTransparency1 = 1
local LabelTransparency = 1
local StrokeTransparency = 1

local Tween4 = TS:Create(StrengthImage, Tweeninfo4, {ImageTransparency = ImageTransparency1})
local Tween5 = TS:Create(StrengthLabel, Tweeninfo4, {TextTransparency = LabelTransparency})
local Tween6 = TS:Create(StrenghtLabelStroke, Tweeninfo4, {Transparency = StrokeTransparency})

WeightTool.Equipped:Connect(function(mouse)
	local character = WeightTool.Parent or player.CharacterAdded:Wait()
	if character then
		humanoid = character:FindFirstChildOfClass("Humanoid")
		if humanoid then
			local AnimatorEquip = humanoid:FindFirstChildOfClass("Animator")
			if AnimatorEquip then
				AnimationTrackEquip = AnimatorEquip:LoadAnimation(StrengthAnimationEquip)
			   if AnimationTrackEquip then
				  AnimationTrackEquip:Play()
				  humanoid.UseJumpPower = true
				  humanoid.JumpPower = 0
				  humanoid.WalkSpeed = 0
				  return AnimationTrackEquip
			   end
			end
		end
	end
end)

WeightTool.Activated:Connect(function()
	local character = WeightTool.Parent or player.CharacterAdded:Wait()
	if character then
		humanoid = character:FindFirstChildOfClass("Humanoid")
		if humanoid then
			local AnimatorActivate = humanoid:FindFirstChildOfClass("Animator")
			if AnimatorActivate then
				AnimationTrackActivate = AnimatorActivate:LoadAnimation(StrengthAnimationActivate)
			   if AnimationTrackActivate then
				  if db == false then
					 db = true
					 AnimationTrackActivate:Play()
					 GainStrengthEvent:FireServer()
					 Tween:Play()
					 TweenLabel:Play()
					 Tween2:Play()
					 Tween3:Play()
					 Tween4:Play()
					 Tween5:Play()	
					 Tween6:Play()
					 task.wait(1.15)
					 db = false
					 return AnimationTrackActivate
				  end
			   end
			end
		end
	end
end)

local ImageTransparency2 = 0
local ImageRotation2 = 0
local Tweeninfo5 = TweenInfo.new(2, Enum.EasingStyle.Back, Enum.EasingDirection.Out, 0, false, 0.5)

local Tween7 = TS:Create(StrengthImage, Tweeninfo5, {ImageTransparency = ImageTransparency2, Rotation = ImageRotation2})

Tween.Completed:Connect(function()
	Tween7:Play()
end)

Basically, i’m trying to make a image label gets a random position on the frame when the player click with the Activate event of the tool and this will make animations like rotation, tweening, and the text label size will grow horizontally and so on.

Note: If you need more information then let me know, thanks!

You’re looking at StarterGui, you should be looking at your player’s PlayerGui. So your code should also interact with PlayerGui instead of StarterGui. I’ve seen a lot of people be confused with the same thing, but now you should never make the same mistake!

local StarterGui = game:GetService("StarterGui")
-- Change to:
local ui = game.Players.LocalPlayer.PlayerGui:WaitForChild("GainStrengthGui")

StarterGui is a folder that the player does not own and when the player dies or joins, the stuff from that folder is copied to the PlayerGui. PlayerGui is a folder owned by the player.
Folder is located:
game:GetService('Players').LocalPlayer:WaitForChild('PlayerGui')

Thanks, i didn’t know that until now, but now i have the problem with the random position :slight_smile:

I don’t know what that means, could you show a new video using the fixed code?

Of course, i’ll fix the transparency effect later:

Oh, I see what you’re trying to do now. Well, you’re making a random position, but you never change it. Therefore it will stay in the same position throughout. There’s so many tweens and variables in your script that I can’t really tell what’s going on. So, I’ll just make a simple script, hoping that you can integrate it easily:

local pos = UDim2.new(math.random(250,750)/1000,0,math.random(400,700)/1000,0)
StrengthUI.StrengthFrame.Position = pos
game.TweenService:Create(StrengthUI.StrengthFrame, Info, {
	Position = pos + UDim2.new(0,0,-0.3,0)
})

I tried something similar but diesn’t work

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