Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

why image thumbnail start at the top instead of the bottom?

Asked by 4 years ago

hi there, I am having a problem with this script. I had implemented the code and it works great to show the thumbnail. problem is that the thumbnail image somehow starts at the top and get down when the player height increases.

is there any way to change it to start at the bottom and work it way up when players' height increases?

here is the script for the leaderstats that records players height

local function OnPlayerJoin(player)

     repeat wait() until player.Character
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player
    local Height = Instance.new("IntValue")
    Height.Name = "Height"
    Height.Parent = leaderstats
    while wait() do Height.Value = (player.Character.HumanoidRootPart.Position.Y - 8) end
end

game.Players.PlayerAdded:Connect(OnPlayerJoin)

here is the script for the thumbnail that will go up and down based on the leaderstat height

local MaxHeight = 200
local Player = game.Players.LocalPlayer
local LeaderStats = Player:WaitForChild("leaderstats")
local Height = LeaderStats:WaitForChild("Height")


local Icon = Instance.new("ImageLabel")
local START_POSITION = UDim2.new(0, 0, 0, 0)
Icon.BackgroundTransparency = 1
Icon.Size = UDim2.new(0.05,0,0.05,0)
Icon.Position = START_POSITION

local RatioConstraint = Instance.new("UIAspectRatioConstraint",Icon)

local UserId = Player.UserId
local ThumbnailType = Enum.ThumbnailType.HeadShot
local ThumbnailSize = Enum.ThumbnailSize.Size420x420
local Thumbnail, isReady = game.Players:GetUserThumbnailAsync(UserId, ThumbnailType, ThumbnailSize)
Icon.Image = Thumbnail
Icon.Parent = script.Parent

local function PlaceIcon()
    Icon:TweenPosition(UDim2.new(0.95,0,(Height.Value/MaxHeight),0),Enum.EasingDirection.In,Enum.EasingStyle.Sine,0.2,true)
end

game:GetService("RunService"):BindToRenderStep("BindPosition", 1, PlaceIcon)

I am wondering what's wrong with the code above that makes the image thumbnail start at the top instead of the bottom.

2 answers

Log in to vote
0
Answered by
oilkas 364 Moderation Voter
4 years ago
Edited 4 years ago

The problem you are facing is that higher the value for Y, lower the image is. You can decrease its value from 1, so the height of the icon becomes directly proportional to the height of the character :) Edit this line:

Icon:TweenPosition(UDim2.new(0.95,0,1 -(Height.Value/MaxHeight),0),Enum.EasingDirection.In,Enum.EasingStyle.Sine,0.2,true)
0
yes thanks your solution works best jacobian65 19 — 4y
0
Happy to help! oilkas 364 — 4y
Ad
Log in to vote
0
Answered by
AlphaY7 -3
4 years ago
Edited 4 years ago

It's because the starting Y value was 0 so it was placed at the top So if you noticed, I made the starting Y value 0.95

    local MaxHeight = 200
    local Player = game.Players.LocalPlayer
    local LeaderStats = Player:WaitForChild("leaderstats")
    local Height = LeaderStats:WaitForChild("Height")

    local Icon = Instance.new("ImageLabel")
    local START_POSITION = UDim2.new(0, 0, 0.95, 0)
    Icon.BackgroundTransparency = 1
    Icon.Size = UDim2.new(0.05,0,0.05,0)
    Icon.Position = START_POSITION

    local RatioConstraint = Instance.new("UIAspectRatioConstraint",Icon)

    local UserId = Player.UserId
    local ThumbnailType = Enum.ThumbnailType.HeadShot
    local ThumbnailSize = Enum.ThumbnailSize.Size420x420
    local Thumbnail, isReady = game.Players:GetUserThumbnailAsync(UserId, ThumbnailType, ThumbnailSize)
    Icon.Image = Thumbnail
    Icon.Parent = script.Parent

    local function PlaceIcon()
        Icon:TweenPosition(UDim2.new(0.95,0,(Height.Value/MaxHeight),0),Enum.EasingDirection.In,Enum.EasingStyle.Sine,0.2,true)
    end

    game:GetService("RunService"):BindToRenderStep("BindPosition", 1, PlaceIcon)
0
I had tried your code above and it still start at the top. what variable I should change to make it start at bottom? jacobian65 19 — 4y

Answer this question