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

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

Asked by
AltNature 169
5 years ago
Edited 5 years ago

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

0
You get the mouse from the Player, not Players User#19524 175 — 5y
0
Now it gives me the error "13:29:44.744 - The current identity (2) cannot create a Player (lacking permission 4)" AltNature 169 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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)
0
It still gives me a error saying "13:36:04.544 - GetMouse is not a valid member of DataModel" AltNature 169 — 5y
0
Try now User#19524 175 — 5y
View all comments (4 more)
0
No errors in the output. Its a normal script. Don't know what's happening. AltNature 169 — 5y
0
ohh should the script be inside the baseplate? AltNature 169 — 5y
0
No, it should be a LOCAL script in StarterPlayerScripts! User#19524 175 — 5y
0
welp im dumb, because I didnt even disable the script and it was disabled.. AltNature 169 — 5y
Ad
Log in to vote
0
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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)

0
But would it be on the axis of the baseplate? AltNature 169 — 5y
0
Error - 13:33:31.037 - Workspace.Script:3: attempt to index local 'plr' (a nil value) AltNature 169 — 5y
0
lol, User#19524 175 — 5y
0
make it a local script Fragmentation123 226 — 5y

Answer this question