Seems like you’re tweening the Image
object instead of the Gui
object.
Ensure it says TweenService:Create(Gui, ...)
Seems like you’re tweening the Image
object instead of the Gui
object.
Ensure it says TweenService:Create(Gui, ...)
Ahh yes, any way to make it slower/smoother?
This may be a challenge, but I am trying to make it so about 10-20-30 of these go flying down, kind of like when you earn something in a game, and it goes up with a bunch of cash. I have learned a lot today about tweening and vector though this is amazing.
Gui:TweenSizeAndPosition(UDim2.fromScale(0.086, 0.061) ,UDim2.fromScale(0.15, 0.15), Enum.EasingDirection.In, Enum.EasingStyle.Linear, 4) --It will tween the Gui to the 0.15, 0.15 Scale position.
If you tell me where to move it, I could better and more help you, @Pooglies
@NovusTheory And @mobyboyy ,never use TweenService for tweening of guis!!! The function :TweePosition
Is specialy for Guis and the TweenService is specialy for 3D Objects, dont use TweenService for 2D Objects, rather use TweenPosition.
Complete and optimal script:
--local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera.ViewportSize
local RE = game.ReplicatedStorage:WaitForChild("Send")
RE.OnClientEvent:Connect(function(player)
print("received")
local Random = Random.new()
function GetRandomPosition(V)
return UDim.fromOffset(Random:NextNumber(V.X, camera.X), Random:NextNumber(V.Y, camera.Y))
end
local camera = workspace.CurrentCamera
local worldPoint = workspace.Part.Position
local Vector, IsOnScreen = camera:WorldToScreenPoint(worldPoint)
if IsOnScreen then
Vector = GetRandomPosition(Vector)
end
--locel Depth = Vector.Z
local screenPoint = UDim2.fromOffset(Vector.X, Vector.Y)
local ScreenGui = Instance.new("ScreenGui", player.PlayerGui)
local Gui = Instance.new("Frame", ScreenGui)
local Image = Instance.new("ImageLabel", Gui)
--local vectorp = screenPoint.Position
Gui.Size = UDim2.new(0.086, 1, 0.061, 1)
Image.Size = UDim2.fromScale(1,1)
Image.Image = "http://www.roblox.com/asset/?id=8057767"
Gui.AnchorPoint = Vector2.new(0.5, 0.5)
Gui.Position = screenPoint
Image.AnchorPoint = Vector2.new(0.5, 0.5)
Image.Position = UDim2.fromScale(0.5, 0.5)
wait(1)
Gui:TweenSizeAndPosition(UDim2.fromScale(0.086, 0.061) ,UDim2.fromScale(0.15, 0.15), Enum.EasingDirection.In, Enum.EasingStyle.Linear, 4) --It will tween the Gui to the 0.15, 0.15 Scale position.
end)
Try it out!
There is absolutely nothing wrong with using TweenService. The GuiObject tween functions are legacy code. TweenService was created to essentially replace it. While they didn’t deprecate the GuiObject one I would encourage using TweenService.
Sorry to hijack here, but for those of you who are unsure about what you’re doing or constantly posting “try this” responses, please try your resolutions out yourself first (and debug them if they do not work) and be sure they actually work so thread replies can be kept at a reasonable amount with answers that tack away at or resolve the problem.
This thread is actually a really good question since some developers (like myself) don’t know how to do this and would like to know how this is done just for an aesthetic touch to a game. Unfortunately it is overly bloated with solutions that don’t work and the relevant information that can be used to work towards the problem is drowned out in those replies.
Cheers.
The issue is that I personally don’t have access to a computer at the moment, so that’s the only thing I can resort to.
@Pooglies, check this new Code out!
Edit: @Pooglies, check out the code Number2!
--local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera.ViewportSize
local RE = game.ReplicatedStorage:WaitForChild("Send")
RE.OnClientEvent:Connect(function(player)
print("received")
[[-- local Random = Random.new()
function GetRandomPosition(V)
return UDim.fromOffset(Random:NextNumber(V.X, camera.X), Random:NextNumber(V.Y, camera.Y))
end--]]
local camera = workspace.CurrentCamera
local worldPoint = workspace.Part.Position
local Vector, IsOnScreen = camera:WorldToScreenPoint(worldPoint)
local ScreenGui = Instance.new("ScreenGui", player.PlayerGui)
local Gui = Instance.new("Frame", ScreenGui)
local RandomX = math.random(0, camera.ViewportSize.X - Gui.AbsoluteSize.X)
local RandomY = math.random(0, camera.ViewportSize.Y - Gui.AbsoluteSize.Y)
if IsOnScreen and RandomX < (Vector.X + 15) and RandomY < (Vector.Y + 15) then
Vector.X = RandomX
Vector.Y = RandomY
end
--locel Depth = Vector.Z
local screenPoint = UDim2.fromOffset(Vector.X, Vector.Y)
local Image = Instance.new("ImageLabel", Gui)
--local vectorp = screenPoint.Position
Gui.Size = UDim2.new(0.086, 1, 0.061, 1)
Image.Size = UDim2.fromScale(1,1)
Image.Image = "http://www.roblox.com/asset/?id=8057767"
Gui.AnchorPoint = Vector2.new(0.5, 0.5)
Gui.Position = screenPoint
Image.AnchorPoint = Vector2.new(0.5, 0.5)
Image.Position = UDim2.fromScale(0.5, 0.5)
wait(1)
Gui:TweenSizeAndPosition(UDim2.fromScale(0.086, 0.061) ,UDim2.fromScale(0.15, 0.15), Enum.EasingDirection.In, Enum.EasingStyle.Linear, 4) --It will tween the Gui to the 0.15, 0.15 Scale position.
end)
--ServerScript
local CollectionService = game:GetService("CollectionService")
for i,v in pairs(workspace:GetChildren())do
if v.Name == "Currency" then
CollectionService:AddTag(v, "Currency")
end
end
--LocalScript
local RE = Istance.new("Remote Event", game.ReplicatedStorage)
RE.Name = "RE"
local player = game.Players.LocalPlayer
while wait(0.01) do
local CollectRadius = 10
local HRP = player.Character.HumanoidRootPart
local CollectionService = game:GetService("CollectionService")
local Currency = CollectionService:GetTagged("Currency")
HRP:GetPropertyChangedSignal("Position"):Connect(function()
if (HRP.Position - Currency.Position).magnitude =< CollecRadius then
RE:FireServer(player)
end
end)
end
--ServerScript
--local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera.ViewportSize
local RE = game.ReplicatedStorage:WaitForChild("Send")
RE.OnClientEvent:Connect(function(player)
print("received")
[[-- local Random = Random.new()
function GetRandomPosition(V)
return UDim.fromOffset(Random:NextNumber(V.X, camera.X), Random:NextNumber(V.Y, camera.Y))
end--]]
local camera = workspace.CurrentCamera
local worldPoint = workspace.Part.Position
local Vector, IsOnScreen = camera:WorldToScreenPoint(worldPoint)
local ScreenGui = Instance.new("ScreenGui", player.PlayerGui)
local Gui = Instance.new("Frame", ScreenGui)
local RandomX = math.random(0, camera.ViewportSize.X - Gui.AbsoluteSize.X)
local RandomY = math.random(0, camera.ViewportSize.Y - Gui.AbsoluteSize.Y)
if IsOnScreen and RandomX < (Vector.X + 15) and RandomY < (Vector.Y + 15) then
Vector.X = RandomX
Vector.Y = RandomY
end
--locel Depth = Vector.Z
local screenPoint = UDim2.fromOffset(Vector.X, Vector.Y)
local Image = Instance.new("ImageLabel", Gui)
--local vectorp = screenPoint.Position
Gui.Size = UDim2.new(0.086, 1, 0.061, 1)
Image.Size = UDim2.fromScale(1,1)
Image.Image = "http://www.roblox.com/asset/?id=8057767"
Gui.AnchorPoint = Vector2.new(0.5, 0.5)
Gui.Position = screenPoint
Image.AnchorPoint = Vector2.new(0.5, 0.5)
Image.Position = UDim2.fromScale(0.5, 0.5)
wait(1)
Gui:TweenSizeAndPosition(UDim2.fromScale(0.086, 0.061) ,UDim2.fromScale(0.15, 0.15), Enum.EasingDirection.In, Enum.EasingStyle.Linear, 4) --It will tween the Gui to the 0.15, 0.15 Scale position.
end)
You’re able to wait until you have access to a computer, I’m sure. It’s better to reply only if you know what you’re suggesting or to leave the thread to be answered by someone who has access to a device with Studio or knows how to resolve this problem.
This prevents the the thread from being clogged up with unworking replies. This thread has already been bloated up to 70 replies (including other try-this posts and ones from OP) when I’m sure it shouldn’t take this many to answer a non-discussion scripting help question.
Does my script work (I can’t try it, am on iPad)?
This is a good question. The process is simple:
collect currency > fire server to remove it > get screen position > create label > tween label to desired position
My implementation would be:
--// server
local event = Instance.new("RemoteEvent")
event.Name = "CurrencyRemove"
event.Parent = game.ReplicatedStorage
event.OnServerEvent:Connect(function(plr, part)
-- could add verification here to prevent exploitation
-- gonna keep this simple, however.
local curr = plr.leaderstats.Money
curr.Value = curr.Value + 10
-- this is the amount of money each part grants.
part:Destroy()
end)
game.Players.PlayerAdded:Connect(function(plr)
-- create leaderstats
local ls = Instance.new("Folder")
ls.Name = "leaderstats"
local m = Instance.new("IntValue", ls)
m.Name = "Money"
ls.Parent = plr
end)
--// client
-- some constants, feel free to play around!
local desired_position = UDim2.new(0, 0, 0, 0) -- where to tween
local tween_time = 1 -- time in seconds to tween
local collection_distance = 5 -- distance in studs to collect currency
local screen_gui = path.to.your.gui
local base_label = Instance.new("ImageLabel")
base_label.ZIndex = 99999 -- render above everything else
base_label.Size = UDim2.new(0, 10, 0, 10)
base_label.Image = "your image here"
base_label.AnchorPoint = Vector2.new(0.5, 0.5)
--[[
NOTE:
Make sure currency is in a Folder named "DroppedCurrency" (excluding quotes)
--]]
local rs = game:GetService("RunService")
local ts = game:GetService("TweenService")
local event = game.ReplicatedStorage.CurrencyRemove
local folder = workspace.DroppedCurrency
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hrp = char:WaitForChild("HumanoidRootPart")
rs.Heartbeat:Connect(function()
for i, part in pairs(folder:GetChildren()) do
if not part:IsA("BasePart") then return end
if (hrp.Position - part.Position).Magnitude <= collection_distance then
event:FireServer(part)
local pos, on_screen = workspace.CurrentCamera:WorldToScreenPoint(part.Position)
-- if the label is offscreen, defaults to the center
local udim
if on_screen then
udim = UDim2.new(0, pos.x, 0, pos.y)
else
udim = UDim2.new(0.5, 0, 0.5, 0)
end
local f = base_label:Clone()
f.Position = udim
f.Parent = screen_gui
local t = ts:Create(
f,
TweenInfo.new(tween_time, Enum.EasingStyle.Sine, Enum.EasingDirection.Out),
{Position = desired_position}
)
t:Play()
t.Completed:Connect(function()
f:Destroy()
end)
-- destroy part locally for that instant feedback
part:Destroy()
end
end
end)
I’ve triple-checked it, so it should be bug-free.
If it doesn’t work, reply with the error and I’ll happily fix it!
Why does everyone use the TweenService to tween guis? But else, it’s like I wrote it. And normally writing a whole and complete code is forbidden, the rest should be taken care of by @Pooglies.
But because you have already started I will also write a complete code (Sometimes is rule crime to do the good)
What is this path and why is it blue?
I am quite confused on this code, I hate to bug you/waste your time, but could you possibly create a game download where I could test it?
TweenService is convenient because it allows the tweening of many different properties for different instances. I always prefer it over GuiObject:TweenPosition()
because of this. Read up on it here if you’re confused
I understand where you’re coming from. In most cases, spoon-feeding code won’t teach anything if the inquisitor only intends on copy+pasting the code, then leaving it. But I do it anyway, mostly because i suck at explaining things without a live code sample.
I wasn’t serious, it’s just a little joke.
@Pooglies, I think this post goes outside the post, you’ve found your answer (nothing bad, but I think we’ve all learned a lot here already)