UI Popup Not Working

I am trying to make a script that when the scripts parent part is touched a “Shop” UI is tweened into the viewport, however I can’t get the script to play on the client. I tried using a local script childed by the part, I’ve tried firing a remote event from the server when the part is touched to the client that plays the tween, and I’ve tried the code as just a script, however none of these worked. I don’t know any other way I could do this, but I know it can be done. Please help!

Here is the script I used;

local tweenService = game:GetService("TweenService")

local shop = game.StarterGui.ShopGUI.ImageLabel

local tweeningInformation = TweenInfo.new(

1, -- Length

Enum.EasingStyle.Linear, -- Easing direction

Enum.EasingDirection.Out, -- Easing direction

0, -- Number of repetitions

false, -- Should tween reverse?

0 -- Length between repetitions

)

local partProperties = {

Position = UDim2.new(0.498, 0, 0.491, 0)

}

local part = script.Parent

part.Touched:Connect(function(HIT)

local H = HIT.Parent:FindFirstChild("Humanoid")

if H then

local player = game.Players:GetPlayerFromCharacter(HIT.Parent)

if player then

local Tween = tweenService:Create(shop, tweeningInformation, partProperties)

Tween:Play()

end

end

end)

I know this can be done, but I can’t figure out why this doesn’t work/how to do it correctly. Please let me know below!

1 Like

This is because you are referencing the GUI in StarterGui rather than the one which is in the players PlayerGui. You can easily fix this by replacing it with this code:

local players = game:GetService("Players")
local player = Players.LocalPlayer
local shop = player:WaitForChild("PlayerGui"):WaitForChild("ShopGUI"):WaitForChild("ImageLabel")

Alright, so now I have this as a local script under the part;

local Players = game:GetService("Players")

local player = Players.LocalPlayer

local shop = player:WaitForChild("PlayerGui"):WaitForChild("ShopGUI"):WaitForChild("ImageLabel")

local tweenService = game:GetService("TweenService")

local tweeningInformation = TweenInfo.new(

1, -- Length

Enum.EasingStyle.Linear, -- Easing direction

Enum.EasingDirection.Out, -- Easing direction

0, -- Number of repetitions

false, -- Should tween reverse?

0 -- Length between repetitions

)

local partProperties = {

Position = UDim2.new(0.498, 0, 0.491, 0)

}

local part = script.Parent

part.Touched:Connect(function(HIT)

local H = HIT.Parent:FindFirstChild("Humanoid")

if H then

local player = game.Players:GetPlayerFromCharacter(HIT.Parent)

if player then

local Tween = tweenService:Create(shop, tweeningInformation, partProperties)

Tween:Play()

end

end

end)

But yet it still doesn’t work. Should I try firing a remote event from the server when the part is touched to the client?

Local scripts do not run when they are in the workspace so instead you can place the script in the GUI, and use this code:

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local shop = script.Parent:WaitForChild("ImageLabel")
local part = workspace:WaitForChild("Part") -- directory to your part

part.Touched:Connect(function(hit)
	if hit:IsDescendantOf(player.Character) then
        -- this is an easier way to tween the position of GuiObjects, rather than using the TweenService
		shop:TweenPosition(UDim2.new(0.498, 0, 0.491, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 1)
	end
end)
1 Like