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

I don't know how to find the name of a player, Can you help me?

Hello I would like to find the name of the person who passes over a block to be able to access its variables and to change it because my game is a tycoon and as in all tycoons there are buttons on the ground to buy any item but I can't get into its variables to decrease his money to pay for the item, I hope you understood. Here is my script:

owner = script.Parent.Parent.Parent.Parent.Owner
owned = script.Parent.Parent.Parent.Parent.Owned
nameplayer = script.Parent.Parent.Parent.Parent.NamePlayer
boddy = script.Parent.Parent.Parent.Parent.Starter.Dropper2.Boddy
part = script.Parent.Parent.Parent.Parent.Starter.Dropper2.drop

script.Parent.Touched:Connect(function(hit)
	if owned.Value == true then
		if owner.Value == hit.Parent.Name then
			nameplayer.Name = hit.Parent.Name
			if game.Players:FindFirstChild('nameplayer'):FindFirstChild("leaderstats").Cash.Value >= 15 then 
				boddy.Transparency = 0
				part.Transparency = 0.5
				game.Players:FindFirstChild('nameplayer'):FindFirstChild("leaderstats").Cash.Value = game.Players:FindFirstChild('hit.Parent.Name'):FindFirstChild("leaderstats").Cash.Value - 15
				script.Parent:Destroy()
			end
		end
	end
end)

1 answer

✓ Accepted answer

You mean trying to find a player if he touches a block? If so:

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then --if the part touched is a player/npc
		if game.Players:FindFirstChild(hit.Parent.Name) then --Checks players to see if a name matches up
			--code here
		end
	end
end)

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