Hello! Long story short, I am trying to make a pizza where you can add toppings. One issue I am having is getting the players mouse position relative to the Frame where the player clicks. The function on line 31 uses Mouse.X and Mouse.Y to get the position which gives different values than the function on line 11 which works. Basically, I am asking how to clone an image on a frame where the player clicks.
local gui = game.Workspace:WaitForChild("Pizza"):WaitForChild("Toppings")
local canvas = gui:WaitForChild("Frame")
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local isMouseDown = false
local lastXPos = 5000
local lastYPos = 5000
local distancePerTopping = 10
canvas.MouseMoved:Connect(function(xPos, yPos)
local paint = game.ReplicatedStorage.Toppings[game.Workspace.Values.SelectedTopping.Value]
if isMouseDown then
if xPos > lastXPos + distancePerTopping or xPos < lastXPos - distancePerTopping or yPos > lastYPos + distancePerTopping or yPos < lastYPos - distancePerTopping then
local paintCloned = paint:Clone()
local offset = Vector2.new(math.abs(xPos - canvas.AbsolutePosition.X), math.abs(yPos - canvas.AbsolutePosition.Y))
paintCloned.Position = UDim2.new(0, offset.X - 15, 0, offset.Y - 15)
paintCloned.Rotation = math.random(0,360)
paintCloned.Parent = canvas
lastXPos = xPos
lastYPos = yPos
end
end
end)
canvas.MouseButton1Click:Connect(function()
local paint = game.ReplicatedStorage.Toppings[game.Workspace.Values.SelectedTopping.Value]
local paintCloned = paint:Clone()
local offset = Vector2.new(math.abs(mouse.X - canvas.AbsolutePosition.X), math.abs(mouse.Y - canvas.AbsolutePosition.Y))
paintCloned.Position = UDim2.new(0, offset.X - 15, 0, offset.Y - 15)
paintCloned.Rotation = math.random(0,360)
paintCloned.Parent = canvas
end)
