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

Turn a instance into a string or?

Asked by
pilotly 15
4 years ago
Edited 4 years ago

Hey, this is my first post and I'm just simply trying to learn why this line of code requires a string and if I can get it to take a variable/instance.

All I'm doing is trying to make a sign change to the player's name when touched.

I do understand that this code does have some stuff that could be shed off but I still can't find out why it wouldn't work.

The line of code I'm having trouble with is

"ourSign.Text = character"

My full code:

local sec15 = script.Parent

local platformg = false

local ourSign = game.Workspace.oursign.SurfaceGui.TextLabel

local function onTouch(partTouched)

local character = partTouched.parent

local humanoid = character:FindFirstChildWhichIsA("Humanoid")   


if character and platformg == false then
    ourSign.Text = character
    platformg = true
end

end

--Event sec15.Touched:Connect(onTouch)

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

Alright so here's what you've got wrong.


if character and platformg == false then --print ("A Humanoid is on me") ourSign.Text = character.Name --you want to set the text to the name of the character, not the character itself! platformg = true end --print ("Character") --print (character)

Basically if you try to set a string value to an object value it's not going to work, you want to use the character name (which is a string value) which you can retrieve using Character.Name

Hope this helps ;)

0
Not exactly sure what all the prints are about, or if i even put them there.. FlabbyBoiii 81 — 4y
Ad

Answer this question