Why does my script position the gui not at the mouse position?

local MouseClickEffect = {}

local function Tween(OBJInstance,Goal,Duration)

local ts = game:GetService("TweenService")

local T = ts:Create(OBJInstance,TweenInfo.new(Duration),Goal)

T:Play()

end

local function Offset(Offset)

return UDim2.fromOffset(Offset.X, Offset.Y)

end

function MouseClickEffect.AddEffect(GUIInstance,Mouse,Duration,Plr)

GUIInstance.ClipsDescendants = false

GUIInstance.AutoButtonColor = false

local MX,MY = Mouse.X,Mouse.Y

local ASX,ASY = GUIInstance.AbsoluteSize.X,GUIInstance.AbsoluteSize.Y

local effect = script.Effect:Clone()

effect.Parent = Plr.PlayerGui

local Pos = GUIInstance.AbsolutePosition

effect.Effect.Position = UDim2.fromOffset(Pos.X,Pos.Y)

effect.Effect.Size = UDim2.fromOffset(ASX,ASY)

effect.Effect.Ripple.Position = Offset(Vector2.new(MX,MY))

local maxsize = math.max(ASX,ASY)*2

effect.Effect.Ripple:TweenSize(UDim2.fromOffset(maxsize,maxsize),"Out","Sine",Duration)

Tween(effect.Effect.Ripple,{BackgroundTransparency = 1},Duration)

wait(Duration)

effect:Destroy()

end

return MouseClickEffect

So the script above position the GUI at a awkward angle and i dont want that and i dont know why it does that for no reason at all so can you please help me

You have shown us the code of the functions involved in the process.
Can you show us the code that calls these functions so we have a full picture.

what do you mean by that? hmm?

I think it’s because you’re changing the position of this “Ripple” (which is a Gui object I suppose) relative to its Parent. If you want the actual mouse position, the frame should be directly inside a ScreenGui or inside a screen size frame

Is this a module script? If so, that is why it isn’t working.

i actually forget to close this topic becuz 2 or 3 hr after this topic i actually fixed the problem :sweat_smile:

Would you care to share the solution?

GuiButtonClickEffect.rbxm (1.1 KB)

1 Like