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

How would I make a mouse.target script not a local script?

Asked by 6 years ago

I'm making a game where if you have a color selected you can click a brick and it changes it to that color. It works fine, but the mouse.target script is a local script. Is it possible to make it a regular script?

0
can you include the script in a code block. User#5423 17 — 6y

2 answers

Log in to vote
-1
Answered by
royee354 129
6 years ago
Edited 6 years ago

If you meant by "regular script" a global script then: to use Mouse.Target in a global script, use a remote event to connect between the local script that will fire the :FireServer() on the remote event and the global script that will use the remote event's OnServerEvent, then you could pass the Mouse.Target variable (game.Players.LocalPlayer:GetMouse().Target) that you will make in the local script from the local script to the global one. You will have to do this because you can't use Mouse(game.Players.LocalPlayer:GetMouse()) in global scripts, but you can pass the mouse's target aslong as you use remote events. https://wiki.roblox.com/index.php?title=Remote_Functions_%26_Events

Ad
Log in to vote
0
Answered by 6 years ago

Hello, barrettr500!

Welcome to the ClickDetector tutorial. A ClickDetector is an object which allows for a part to be clicked. They are server-side only, so you can use this instead of a mouse’s Target property. The ClickDetector.MouseClick event is the event that captures the mouse click on its BasePart parent.

--Server script inside of a part
local part = script.Parent
local clickDetector = Instance.new("ClickDetector", part)

clickDetector.MouseClick:Connect(function(plr) -- player passed 
    print(plr.Name)

    --do your brick color changing code here 
end)

Answer this question