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

Part placing - GetMouse() is not a valid member of players?

I'm making it that there is a ClickDetector inside the Baseplate, and that if you click on the baseplate, then a part will appear wherever you click, but it seems to not work and gives me the error - > GetMouse is not a valid member of players.

Here is my script.

local b = script.Parent.Baseplate
local plr = game:GetService("Players")
local mouse = plr:GetMouse()

b.ClickDetector.MouseClick:Connect(function()
	local part = Instance.new("Part")
	 part.Position = mouse.Position
end)

I'm also confused as to how I would put it on the axis of the base plate EDIT

2 comments

0

You get the mouse from the Player, not Players

0

Now it gives me the error "13:29:44.744 - The current identity (2) cannot create a Player (lacking permission 4)"

2 answers

✓ Accepted answer

###You get the mouse from the Player object, not from the Players service. Also, the property for mouse position is called Hit. You'll want to place this code in a local script under StarterPlayerScripts.

wait()

local plr = game:GetService("Players").LocalPlayer
local mouse = plr:GetMouse()
local UIS = game:GetService("UserInputService")

local function onMouseDown(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        local part = Instance.new("Part")  
        part.Position = mouse.Hit.p
        part.Parent = workspace 
    end
end

UIS.InputBegan:Connect(onMouseDown)

8 comments

0

It still gives me a error saying "13:36:04.544 - GetMouse is not a valid member of DataModel"

0

Try now

0

No errors in the output. Its a normal script. Don't know what's happening.

0

ohh should the script be inside the baseplate?

0

No, it should be a LOCAL script in StarterPlayerScripts!

0

welp im dumb, because I didnt even disable the script and it was disabled..

GetMouse is not a valid function of the players service, but it is for the client. Also, the position for the mouse is Mouse.Hit.p

local b = script.Parent.Baseplate
local plr = game:GetService("Players").LocalPlayer
local mouse = plr:GetMouse()
 
b.ClickDetector.MouseClick:Connect(function()
	local part = Instance.new("Part")
	part.Position = mouse.Hit.p
end)

4 comments

0

But would it be on the axis of the baseplate?

0

Error - 13:33:31.037 - Workspace.Script:3: attempt to index local 'plr' (a nil value)

0

lol,

0

make it a local script

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