Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Mouse clicks, clone doesn't go to Position of Mouse?

Hi, I'm currently making a editor for my game in Roblox, and when you click it's meant to place a object, but it doesn't do that. This is the code, if you can fix it in some way, that would be seriously helpful.

local UserInputService = game:GetService('UserInputService')

UserInputService.InputBegan:connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		local Mouse = game.Players.LocalPlayer:GetMouse()
		local CloneHitCircle = script.Parent.PlaceHitCircle:Clone()
		print("Mouse clicked, clone added.")
		CloneHitCircle.Image = 'rbxgameasset://Images/Hit_Circle'
		CloneHitCircle.Parent = script.Parent
		CloneHitCircle.Name = "HitCircle"
	   CloneHitCircle.Position = UDim2.new(Mouse.X, Mouse.Y)
		end
end)

1 answer

Hey just a heads-up, that should definitely error, if it isn't erroring then your code isn't running, anyways here's the script.

local UserInputService = game:GetService('UserInputService')
local Mouse = game.Players.LocalPlayer:GetMouse() -- define it outside of event.

UserInputService.InputBegan:connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        local CloneHitCircle = script.Parent.PlaceHitCircle:Clone()
        print("Mouse clicked, clone added.")
        CloneHitCircle.Image = 'rbxgameasset://Images/Hit_Circle'
        CloneHitCircle.Parent = script.Parent
        CloneHitCircle.Name = "HitCircle"
       CloneHitCircle.Position = UDim2.new(Mouse.Hit.X, Mouse.Hit.Y) -- Mouse.Hit, not Mouse
        end
end)

6 comments

0

Thank you!

0

I tested this, it didn't work. I don't know why but it just didn't work.

0

thanks for ignoring what I said "script isn't running".

0

Uh. I didn't ignore it and also my localscript was running.

0

I actually found other ways to do this using Instance.new so yeah.

0

yikes.

This discussion is preserved as it was. New answers, comments, and votes are closed.