I want it so when I click the play button where ever my mouse is on that button i want the shockwave to originate from:
local TweenService = game:GetService("TweenService")
local PlayerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
local button = script.Parent -- Ensure this is the correct reference to your button
-- Function to create a shockwave effect
local function createShockwave(localMousePos)
local shockwave = Instance.new("Frame")
shockwave.Size = UDim2.new(0, 0, 0, 0)
shockwave.Position = UDim2.new(0, localMousePos.X, 0, localMousePos.Y)
shockwave.AnchorPoint = Vector2.new(0.5, 0.5)
shockwave.BackgroundTransparency = 0.5
shockwave.BackgroundColor3 = Color3.fromRGB(255, 0, 0) -- Red color for visibility
shockwave.BorderSizePixel = 0
shockwave.ZIndex = 10
shockwave.Parent = PlayerGui -- Add to PlayerGui
-- Make the shockwave circular
local uiCorner = Instance.new("UICorner")
uiCorner.CornerRadius = UDim.new(1, 0)
uiCorner.Parent = shockwave
-- Animate the shockwave
local sizeTween = TweenService:Create(shockwave, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {Size = UDim2.new(0, 150, 0, 150)})
local transparencyTween = TweenService:Create(shockwave, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {BackgroundTransparency = 1})
sizeTween:Play()
transparencyTween:Play()
transparencyTween.Completed:Connect(function()
shockwave:Destroy()
end)
end
-- Function to handle the button click
local function onButtonClick()
local mouse = game.Players.LocalPlayer:GetMouse()
local mouseX = mouse.X
local mouseY = mouse.Y
-- Convert screen coordinates to GUI coordinates
local guiObject = button.Parent
local guiSize = guiObject.AbsoluteSize
local guiPos = guiObject.AbsolutePosition
local relativeX = mouseX - guiPos.X
local relativeY = mouseY - guiPos.Y
if relativeX >= 0 and relativeX <= guiSize.X and relativeY >= 0 and relativeY <= guiSize.Y then
createShockwave(Vector2.new(relativeX, relativeY))
else
warn("Click outside the GUI bounds")
end
end
button.MouseButton1Click:Connect(onButtonClick)