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

How do I make an value replicate from an tool to an gui on click?

Asked by 3 years ago
Edited 3 years ago

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)

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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)
0
Thanks for answering, but the grab tool's name isn't "grab tool" if I change it it'll still work, right? Pancio10_alt 4 — 3y
0
yes it should kingblaze_1000 359 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

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)
0
The problem is it's not an text box, gui has also an value which is also called "Suspect" Pancio10_alt 4 — 3y
0
As a coder you need to look to be more efficient. kingblaze_1000 359 — 3y
0
If its not a text gui, how are you displaying it? WizyTheNinja 834 — 3y
0
he said "part" kingblaze_1000 359 — 3y
View all comments (2 more)
0
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. WizyTheNinja 834 — 3y
0
instead of gui.text, just modify the gui.Suspect.Value into it. If thats not what you want then I completely misunderstood your post. WizyTheNinja 834 — 3y

Answer this question