In a tool, I want to use the activate function to do something at the mouse's position when clicked. it is fairly easy to do inside of a local script, but I can't seem to do it with a regular script. I tried doing
script.Parent.Activated:connect(function(mouse) Part = Instance.new("Part", workspace) Part.Position = mouse.Hit.Position end)
but the parameter of the function doesn't seem to be the actual mouse. Doing this with a local script is just
Mouse = game.Players.LocalPlayer:GetMouse()
and that's that, but I need it with a regular script because the script I want to run doesn't work with a local script.
If this answers your question, then mark it as the accepted answer please.
What you will need is a remote event, it allows the server to do stuff given a command from a local script.
regular script
local ReplicatedStorage = game:GetService("ReplicatedStorage") local remoteEvent = Instance.new("RemoteEvent", ReplicatedStorage) remoteEvent.Name = "WhateverYouWantToNameIt" local function onRemoteEventFired(player,pos) local Part = Instance.new("Part") Part.Parent = game.Workspace--second arg of Instance.new() is deprecated, do this instead Part.Position = pos end remoteEvent.OnServerEvent:Connect(onRemoteEventFired)
local script
local ReplicatedStorage = game:GetService("ReplicatedStorage") local remoteEvent = ReplicatedStorage:WaitForChild("WhateverYouWantToNameIt") script.Parent.Activated:connect(function(mouse) remoteEvent:FireServer(mouse.Hit.Position) end)
So you have the mouse click handled by the client and the stuff inside that function handled by the server.
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() script.Parent.Parent.Activated:Connect(function() local Part = Instance.new("Part") Part.Parent = workspace Part.Position = Mouse.hit.Position end)