I am trying to make it so that when the you enter the area with a non-collision part, a shop GUI tweens in, and when you leave the area the shop GUI tweens out.
local replicatedstorage = game:GetService('ReplicatedStorage')
script.Parent.Touched:Connect(function(hit)
print("test1")
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player and not game.StarterGui.ShopGui.Frame.Visible then
print("test2")
replicatedstorage:WaitForChild('TouchingShop'):FireClient(player)
end
end)
script.Parent.TouchEnded:Connect(function(hit)
print("test3")
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player and game.StarterGui.ShopGui.Frame.Visible then
print("test4")
replicatedstorage:WaitForChild('NotTouchingShop'):FireClient(player)
end
end)
The problem is that all the print statements start firing randomly, and the TouchEnded should only be firing when you leave the part, but it does it rapidly while you are inside it.
Here are my GUI tween scripts:
Popup Script:
script.Parent.Frame.Visible = false
script.Parent.Frame.Position = UDim2.new(0.182, 0,-1.163, 0)
local frame = script.Parent.Frame
local replicatedstorage = game:GetService('ReplicatedStorage')
replicatedstorage:WaitForChild('TouchingShop').OnClientEvent:Connect(function()
print("Shop opened")
frame.Visible = true
frame:TweenPosition(UDim2.new(0.182, 0,0.163, 0))
end)
My shop GUI doesnât open either, and the code isnât working since itâs not printing âShop openedâ
Close script:
local replicatedstorage = game:GetService('ReplicatedStorage')
local frame = script.Parent.Frame
replicatedstorage:WaitForChild('NotTouchingShop').OnClientEvent:Connect(function()
frame:TweenPosition(UDim2.new(0.182, 0,-1.163, 0), "In", "Quint", 1)
wait(2)
frame.Visible = false
end)
Iâve attempted to use answers from these posts but they didnât work, the TouchEnded still fires when youâre inside the part.
How can I fix my scripts so that it works?
EDIT: Iâve removed the Visibility part from the script but the problem persists
EDIT 2: Iâve made it all client sided
It still has issues though, as it keeps randomly disappearing
robloxapp-20200410-1646453.wmv
EDIT 3: I used magnitude instead of touched, the GUI works now