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

How can i make a script that fires if the players name is equal to a stringvalue value ?

Hello, i am trying to make it so that when a part is touched and that the name of the player that touched the part is equal to a stringvalue value then it fires a script. Thank you and merry christmas.

currentowner = script.Parent.Parent.CurrentOwner

script.Parent.Parent.PartFire.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid")then
if hit.Parent.Name == currentowner.Value then
			print ("hello world")
		end
end)

:)

1 answer

✓ Accepted answer

Hello! This is how you do it, Enjoy and merry christmas.

Script:

local CO = script.Parent.Parent.CurrentOwner -- Gets the string value

script.Parent.Parent.PartFire.Touched:Connect(function(P) -- Connects the function when the part is touched
local PL = game.Players:GetPlayerFromCharacter(P.Parent) -- Gets player

if PL then -- Checks if there is a player
if PL.Name == CO.Value then -- Checks if the player's name is equal to the current owner's value
-- Code here
end
end
end)

3 comments

0

Thank you ! Have a good one :)

0

No problem! You too :)

0

Could you please add me on discord ? I am trying to make a game and learn a bit of lua on the way and if you can help me i'll be really happy :) Baguette#0077

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