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

How do you make a block that if touched then the other part changes its text?

Asked by 2 years ago

Heres my script right now but it doesnt work

--Variables--
local Brick = script.Parent
local OtherBrick = game.Workspace.Part
local player = game.Players.LocalPlayer
--End--

--Code--
local function PlayerTouched(Part)
    local Parent = Part.Parent
    OtherBrick.SurfaceGui.TextLabel.Text = ""..player.Name..""
end
end

Brick.Touched:connect(PlayerTouched)

2 answers

Log in to vote
0
Answered by 2 years ago

Put this in a script in a part

function onTouched(part) -- function player humanoid touch part

 local h = part.Parent:findFirstChild("Humanoid")

    if h~=nil then

        script.Parent.SurfaceGui.TextLabel.Text = "hi" --changes text

        h.Text = "hi"--changes text



 end

end

script.Parent.Touched:connect(onTouched) --activated on touch

Make sure you have surfacegui in the part with a text lable inside the surface gui

Ad
Log in to vote
0
Answered by 2 years ago

If you are looking for the username of the player who touched the part, you would need a StringValue to access it. This is how I would advise you to do it.

First, put a script in your "OtherBrick" and put a StringValue in the script. Copy and paste the following code into this new script.

while wait() do
    script.Parent.Text = script.Value.Value
end

Then you would add this script into your touched brick.

OtherBrick = game.Workspace.Part

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        OtherBrick.SurfaceGui.TextLabel.Script.Value.Value = hit.Parent.Name
    end
end)

I would recommend changing the "OtherBrick" part name distinctly, due to lots of objects being named "Part" in most games. If you do change it, remember to change line 1's "Part" to whatever you name it.

Hopefully this works for you!

Answer this question