Hello, it's for my arrest system. When you grab someone, his name appears in "suspect" value inside the grab tool, how do I make it replicate to an gui when player clicks an part, the value from grab tool will be same as in gui? (it shows up gui when you click an part but suspect value in gui is nil)
So first of all you will need a ClickDetector
inside your part. Detecting a click from a ClickDetector
is the same as detecting a click from a gui button.
local part = --//Path to part part.ClickDetector.MouseButton1Click:Connect(function(plr) --//plr is the player object end)
Then you will need to transfer the player's name into the StringValue
you've stored in your grab tool.
local grab_tool = --//Path to grab tool local val = grab_tool.suspect val.Value = plr.Name
Then the you will need to set the text property of the gui object to whatever the value inside your suspect
object is, in this case, it will be the name of the player.
local gui_text = --//Path to the object you want to replicate the value to gui_text.Text = val.Value
Altogether, it will look something like this:
local part = --//Path to part local grab_tool = --//Path to grab tool local val = grab_tool.suspect local gui_text = --//Path to the object you want to replicate the value to part.ClickDetector.MouseButton1Click:Connect(function(plr) val.Value = plr.Name --//You can also skip a step by removing this line gui_text.Text = plr.Name end)
There is an easier way to approach it than with kingblaze's answer. His will work however there is no need for click detectors or anything. Just simply detect a player click, and see if certain criteria is met. If so display gui.
-- Inside a local script local player = game.Players.LocalPlayer -- Get the player local mouse = player:GetMouse() -- Get the players mouse local gui = --Change to where your textbox is located that will be changed. mouse.Button1Down:Connect(function() -- Detect when player clicks if player.Character:FindFirstChild("GrabTool") then -- Check to see if player has the grab tool equipped. Change "GrabTool" to the name of the tool. if player.Character.GrabTool.NameToTransfer.Value ~= "" then -- Check to see if the string value isn't blank. If it isn't continue with code. gui.Text = player.Character.GrabTool.NameToTransfer.Value.Name -- If name isn't blank, update gui text. end end end)