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

Can i have help with a ontouched change textlabel text?

Asked by 6 years ago
Edited 6 years ago

(Before reading this, please notice I am a horrible scripter as I just started a few months ago)

So I'm trying to do a Ontouched Change TextLabel Text script and I can't figure it out

I'm trying to make it so if you touch a part it changes a text on you're screen. To guide you through the game, and I can't figure it out.

my script is gonna be stupid as I'm still new to scripting

function onTouch(hit)
game.workspace.StarterGui.Frame.TextLabel.Text = ("Example")
end

script.Parent.Touched:connect(onTouch)

0
are your using filterenabled? Nickelz 37 — 6y
0
nope. ment34591 20 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago
workspace.Part.Touched:connect(function(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
        plr.PlayerGui.ScreenGui.Frame.TextLabel.Text = "adasdasda"
end)

change first line to whatever your part is change the last line to whatever your things are called and it should work

1
ComradeREKTangle legit solved my problem thanks alot ment34591 20 — 6y
Ad
Log in to vote
0
Answered by
Leamir 3138 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

Hello, ment34591!

I think i know how to solve your problem!

A gui is on the "StarterGui" to be added to new players that join, if the player is already on the game, you have to acces player's gui object =D

This script will change the text of the player that touched!

function onTouch(hit) 
    if game.Players:FindFirstChild(hit.Parent.Name) then
        game.Players[hit.Parent.Name].PlayerGui.Frame.TextLabel.Text = "Example"
    end
end

script.Parent.Touched:connect(onTouch)

This one will change the gui of all players

function onTouch(hit) 
    for i,plr in pairs(game.Players:GetChildren) do
        game.Players[plr.Name].PlayerGui.Frame.TextLabel.Text = "Example"
    end

end

script.Parent.Touched:connect(onTouch)

Hope this helps

Good Luck with your games!

0
15:23:33.243 - HumanoidRootPart is not a valid member of Players ment34591 20 — 6y
0
This is a error of another script, the ones I made don't get the "HumanoidRootPart", so, this can't be the error Leamir 3138 — 6y
0
it is ment34591 20 — 6y
0
it`s impossible to get an error with HumanoidRootPart if i don`t even call it on the script Leamir 3138 — 6y
View all comments (4 more)
0
its not a member of players ment34591 20 — 6y
0
oh, now i see, i'll solve it Leamir 3138 — 6y
0
solved, try now Leamir 3138 — 6y
0
ill accept for no reason ment34591 20 — 6y

Answer this question