Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
harstud 218 Moderation Voter
4 years ago

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

Log in to vote
0
Answered by
Elixcore 1337 Moderation Voter
4 years ago

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)
0
Thank you! harstud 218 — 4y
0
I tested this, it didn't work. I don't know why but it just didn't work. harstud 218 — 4y
0
thanks for ignoring what I said "script isn't running". Elixcore 1337 — 4y
0
Uh. I didn't ignore it and also my localscript was running. harstud 218 — 4y
View all comments (2 more)
0
I actually found other ways to do this using Instance.new so yeah. harstud 218 — 4y
0
yikes. Elixcore 1337 — 4y
Ad

Answer this question