idk who downvoted you, I thought it was a reasonable question...
first off, you need to be using a local script in order to get Mouse.Hit.p
local script
light=Instance.new("Part",game.Workspace)
light.Position=mouse.Hit.p
Now, we have to access the local player and store it into a variable
local player = game.Players.LocalPlayer
light=Instance.new("Part",game.Workspace)
light.Position=mouse.Hit.p
Next, create a variable to store the mouse. With the local player we can use a special method by the name of LocalPlayer:GetMouse()
Check out more info about accessing the mouse here:
http://wiki.roblox.com/index.php?title=API:Class/Mouse
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
light=Instance.new("Part",game.Workspace)
light.Position=mouse.Hit.p
Finally, lets add a MouseButton1Down event to determine when to reset the brick position
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.MouseButton1Down:connect(function()
light=Instance.new("Part",game.Workspace)
light.Position=mouse.Hit.p
end)
The above script should now work fine, but we forgot one important thing with this. Filtering Enabled! If we go to game.Workspace and look at the workspace properties, there should be a filtering enabled checkbox. When developing a game, we want to have that enabled so that hackers and exploiters can't mess up our game from their computer. This does leave us with a downfall, however. We cannot access or change things in the workspace such as creating a part in the above script, because filtering enabled will think we are a hacker. To prove that we are a local script running on the client, we have to use remote functions to create the new part and set it's position to where the mouse clicked
Filtering Enabled Tutorial:
http://wiki.roblox.com/index.php?title=Client-Server_Model_and_FilteringEnabled <- this will have a more in depth coverage of how filtering enabled works, and some visuals to help you understand it.
http://wiki.roblox.com/index.php?title=RemoteFunction_and_RemoteEvent_Tutorial remote function and remote event tutorial here
For now lets add a remote function and insert parts of our script into a server script under workspace.
serverscript
light=Instance.new("Part",game.Workspace)
light.Position=mouse.Hit.p
local script
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
Now we can create a remote function to link the two scripts...
serverscript
local part = Instance.new("Part", game.Workspace)
myRemoteFunction.Parent = game.Workspace
myRemoteFunction.Name = "MyRemoteFunction"
function myRemoteFunction.OnServerInvoke(pos)
part.Position = pos
end
local script
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.MouseButton1Down:connect(function()
game.Workspace.MyRemoteFunction:InvokeServer(mouse.Hit.p)
end)
Hope that helps! Let me know if anything doesn't work and I will fix it asap!
1 comment
ty