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)
How do I make an value replicate from an tool to an gui on click?
2 answers
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)
6 comments
The problem is it's not an text box, gui has also an value which is also called "Suspect"
As a coder you need to look to be more efficient.
If its not a text gui, how are you displaying it?
he said "part"
He stated that he had a gui that was nil when he clicked the part. From my understanding of his post, he wanted a gui to display the players name. Regardless my code would be easy to modify into what he wants, if he chooses to.
instead of gui.text, just modify the gui.Suspect.Value into it. If thats not what you want then I completely misunderstood your post.
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Thanks for answering, but the grab tool's name isn't "grab tool" if I change it it'll still work, right?
yes it should