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

How to save the name of who touched a brick?

Asked by 10 years ago

So I am working on a City Roleplaying game. Mainly to practice my scripting abilities. But I have run into a little problem. I can not figure out how to save the name of a Player who touched a brick. So I have a door and you walk into it to become the owner, how do I save the name of whoever touched the door so I can make them become the owner? So in short all I need is to find out how to tell who touched the door and is it local script or server script? So far this is all I have, I need this save thing before I can continue.

local Door = script.Parent
local Name = script.Parent.House.SurfaceGui.TextLabel.Text

function whotouched(hit)

end


3 answers

Log in to vote
0
Answered by 10 years ago

Okay, try this. I've explained it in comments.

local Door = script.Parent
local Name = script.Parent.House.SurfaceGui.TextLabel.Text

function whotouched(hit)
    if hit.Parent.Humanoid ~= nil --Makes sure the hit object has a humanoid, to make sure that brick's don't register.
        Name = hit.Parent.Parent.Name.." owns this house." --Targets the player (the "hit" connects to the limb that touched the brick, so we have to use Hierarchy to find the Player instance) and sets the text to the player's name.
    end
end

Door.Touched:connect(whotouched)


Btw, hello Nexus. :3

Ad
Log in to vote
0
Answered by
war8989 35
10 years ago

Use a StringValue to store the name of the owner of the house. Use the following code:

Owner = script.Owner
script.Parent.Touched:connect(function(hit)
    humanoid = hit.Parent:findFirstChild("Humanoid")
    if(humanoid ~= nil) then
        Owner.Value = hit.Parent.Name
    end
end)
0
Place this script as a child of the part that should be touched. Insert a StringValue called "Owner" as a child of this script. war8989 35 — 10y
Log in to vote
-1
Answered by 10 years ago
function onTouch(hit)
if hit.Parent.Humanoid ~= nil then --If a humanoid(Player) Touched it
game.Humanoid.hit.Name:SaveName --Save the name
        end
end
Part.Touched:connect(onTouch) --Change part to what you wanted it to be

Answer this question