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