so what im trying to do is a mini game where the cyan frame moves forward and then backward, and when the player clicks his mouse the cyan frame stop moving, and then you check if the cyan frame is touching any of the green frames, but the problem is that its not working, i tried using
but its not working for some reason, heres the script:
local TweenService = game:GetService("TweenService")
local UserInputService = game:GetService("UserInputService")
local MovingFrame = script.Parent
local Info = TweenInfo.new(.85, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, true,0)
local Goal = {Position = UDim2.new(0.969, 0,-0.282, 0)}
local Tween = TweenService:Create(MovingFrame, Info, Goal)
local function StartMoving()
Tween:Play()
local Loop = Tween.Completed:Connect(function()
Tween:Play()
end)
return Loop
end
local Loop
Loop = StartMoving()
UserInputService.InputBegan:Connect(function(key)
if key.UserInputType == Enum.UserInputType.MouseButton1 then
Loop:Disconnect()
Tween:Pause()
print(game.Players.LocalPlayer.PlayerGui:GetGuiObjectsAtPosition(MovingFrame.Position.X.Offset, MovingFrame.Position.X.Offset))
wait(.5)
Loop = StartMoving()
end
end)
It could be that you’ll need to use AbsolutePosition instead:
local TweenService = game:GetService("TweenService")
local UserInputService = game:GetService("UserInputService")
local MovingFrame = script.Parent
local Info = TweenInfo.new(.85, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, true,0)
local Goal = {Position = UDim2.new(0.969, 0,-0.282, 0)}
local Tween = TweenService:Create(MovingFrame, Info, Goal)
local function StartMoving()
Tween:Play()
local Loop = Tween.Completed:Connect(function()
Tween:Play()
end)
return Loop
end
local Loop
Loop = StartMoving()
UserInputService.InputBegan:Connect(function(key)
if key.UserInputType == Enum.UserInputType.MouseButton1 then
Loop:Disconnect()
Tween:Pause()
print(game.Players.LocalPlayer.PlayerGui:GetGuiObjectsAtPosition(MovingFrame.AbsolutePosition.X, MovingFrame.AbsolutePosition.Y))
wait(.5)
Loop = StartMoving()
end
end)
The AbsolutePosition is dependant on the frame’s anchor point, so it might be the case that we need to offset the value according to the frame’s AbsoluteSize as well if the anchor point isn’t set to 0.5, 0.5
It could be happening due to the top-bar’s offset, so this might work:
local TweenService = game:GetService("TweenService")
local UserInputService = game:GetService("UserInputService")
local GuiService = game:GetService("GuiService")
local MovingFrame = script.Parent
local Info = TweenInfo.new(.85, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, true,0)
local Goal = {Position = UDim2.new(0.969, 0,-0.282, 0)}
local Tween = TweenService:Create(MovingFrame, Info, Goal)
local function StartMoving()
Tween:Play()
local Loop = Tween.Completed:Connect(function()
Tween:Play()
end)
return Loop
end
local Loop
Loop = StartMoving()
UserInputService.InputBegan:Connect(function(key)
if key.UserInputType == Enum.UserInputType.MouseButton1 then
Loop:Disconnect()
Tween:Pause()
print(game.Players.LocalPlayer.PlayerGui:GetGuiObjectsAtPosition(MovingFrame.AbsolutePosition.X, MovingFrame.AbsolutePosition.Y - GuiService:GetGuiInset().Y))
wait(.5)
Loop = StartMoving()
end
end)
A test you can try is to compare the frame’s position and absolute position with the mouse’s position, and alternatively setting the offset value manually to a value such as 36
@TypicalCEO I found a post on the forum of an issue with GetGuiObjectAtPosition not detecting a Gui that has Active set to true, maybe that’s what causing the problem to happen?
ok from what i understood :GetGuiObjectsAtPosition only works for mouse position, so what i instead did is i used a module called “GuiCollisionService” made by @jaipack17
and i did the following script
local TweenService = game:GetService("TweenService")
local UserInputService = game:GetService("UserInputService")
local GuiCollisionService = require(game:GetService("ReplicatedStorage").COLLISION_SERVICE.GuiCollisionService)
local GuiService =game:GetService("GuiService")
local DeathGroup = GuiCollisionService.createCollisionGroup()
DeathGroup:addHitter(script.Parent, { })
local player = DeathGroup:getHitter(1)
local MovingFrame = script.Parent
local Info = TweenInfo.new(.85, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, true,0)
local Goal = {Position = UDim2.new(0.969, 0,.5, 0)}
local Tween = TweenService:Create(MovingFrame, Info, Goal)
local function StartMoving()
Tween:Play()
local Loop =Tween.Completed:Connect(function()
Tween:Play()
end)
return Loop
end
local Loop
local Paused = false
Loop = StartMoving()
for i,v in pairs(script.Parent.Parent:GetChildren()) do
if v.Name == "CorrectArea" then
DeathGroup:addCollider(v, false)
end
end
UserInputService.InputBegan:Connect(function(key)
if key.UserInputType == Enum.UserInputType.MouseButton1 then
Loop:Disconnect()
Tween:Pause()
Paused = true
wait(1)
Paused = false
Loop = StartMoving()
end
end)
player.CollidersTouched.Event:Connect(function(hits)
for i,v in pairs(hits) do
if v.Name == "CorrectArea" and Paused == true then
print('HIT Green Bar')
end
end
end)