Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can i have help with a ontouched change textlabel text?

(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)

2 comments

0

are your using filterenabled?

0

nope.

2 answers

✓ Accepted answer
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 comment

1

ComradeREKTangle legit solved my problem thanks alot

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!

8 comments

0

15:23:33.243 - HumanoidRootPart is not a valid member of Players

0

This is a error of another script, the ones I made don't get the "HumanoidRootPart", so, this can't be the error

0

it is

0

its impossible to get an error with HumanoidRootPart if i dont even call it on the script

0

its not a member of players

0

oh, now i see, i'll solve it

0

solved, try now

0

ill accept for no reason

This discussion is preserved as it was. New answers, comments, and votes are closed.