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

How to activate a tool and get the mouse's hit with a normal script?

Asked by 4 years ago
Edited 4 years ago

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.

2 answers

Log in to vote
1
Answered by
SteamG00B 1633 Moderation Voter
4 years ago
Edited 4 years ago

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.

0
Didn't work mate. What I'm looking for is to only use a regular script, because doing what I want the script to actually do won't work with a local one. I tried using your regular script, and it didn't work. I tried using both at once and it didn't work. I'll try experimenting with your advice. Thanks in advance. newton162 5 — 4y
0
No, you need to do everything I've gone over in my solution, it doesn't work if you only pick and choose. SteamG00B 1633 — 4y
0
Put the regular script inside server script service and the local script inside your tool SteamG00B 1633 — 4y
0
Aw man! That tutorial I was watching was getting itneresting. I put the regular script into ServerScriptService and sure enough.. it didn't work! I fixed it though. Your local script had a slight error. Thanks mate. I'll see if the script I want to run will run now, and if it does I'll mark your answer. newton162 5 — 4y
View all comments (5 more)
0
You don't have to be snide about this, I didn't need to spend part of my day answering your question, I did this for your benefit. There is nothing wrong with my answer, and whether you decide to do it or not is up to you, but it solves your question, so mark it as the accepted answer. SteamG00B 1633 — 4y
0
ugh i have to do pairs and stuff hold up newton162 5 — 4y
1
@newton162 Dude, you can not put parts into Workspace via purely client script and make it show for all users now. It's part of Roblox's FilteringEnabled security which keeps products of a client reserved to the client. If you want a part to be placed in Workspace, then you'd have to use a client AND server script. Any tutorials dating pre-July of 2018 are going to be useless. M39a9am3R 3210 — 4y
0
that was in the tutorial. Local being locally, as in all, right? Sorry im dumb newton162 5 — 4y
0
Local script means a script run entirely by the client, a regular script is a script run entirely by the server. You can't mix them without remote events or functions. SteamG00B 1633 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
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)
0
i said NORMAL script not a local one newton162 5 — 4y

Answer this question