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

How do I make a working player-name identification script?

Backstory: I am trying to make a group door in my game that uses an open/close script like this (it does work):

local isOpen = false

function Open()
	workspace.Door.door.Transparency=(0.7)
	workspace.Door.door.CanCollide=false
	workspace.Door.window.CanCollide=false
	workspace.Door.caution.CanCollide=false
	workspace.Door.caution.Transparency=(0.7)
	wait(0.9)
	isOpen = true
	workspace.Door.door.Transparency=(0)
	workspace.Door.door.CanCollide=true
	workspace.Door.window.CanCollide=true
	workspace.Door.caution.CanCollide=true
	workspace.Door.caution.Transparency=(0)
	isOpen = false
end

workspace.Door.sensor.Touched:Connect(Open)

Problem: I have tested the group door script in my door many times, and it is obvious that it stops around line 9. The Lua debugger has shown no issues with the script whatsoever, and I can't figure out what's wrong with it. The main thing I need to figure out is how to get the Player.Name to a variable that can be used on Line 9. Here is the script:


local isOpen = false
local playerName = ""

script.Parent.Touched:Connect(function(hit)
    local player=game:GetService('Players'):GetPlayerFromCharacter(hit.Parent)
    if player then
    	playerName = (player.Name)
		print(player.Name)
		if game.Players[playerName]:IsInGroup(289530) == true then 
			workspace.gDoor.door.Transparency=(0.7)
			workspace.gDoor.door.CanCollide=false
			workspace.gDoor.window.CanCollide=false
			workspace.gDoor.caution.CanCollide=false
			workspace.gDoor.caution.Transparency=(0.7)
			wait(0.9)
			isOpen = true
			workspace.gDoor.door.Transparency=(0)
			workspace.gDoor.door.CanCollide=true
			workspace.gDoor.window.CanCollide=true
			workspace.gDoor.caution.CanCollide=true
			workspace.gDoor.caution.Transparency=(0)
			isOpen = false	
			
		end
    end
end)



1 answer

Hello!

You don't actually need a few things in your script.

local isOpen = false

script.Parent.Touched:Connect(function(hit)
    local player=game:GetService('Players'):GetPlayerFromCharacter(hit.Parent)
    if player then
        print(player.Name)
        if player:IsInGroup(289530) then --you don't need to search for the player
            workspace.gDoor.door.Transparency=(0.7)
            workspace.gDoor.door.CanCollide=false
            workspace.gDoor.window.CanCollide=false
            workspace.gDoor.caution.CanCollide=false
            workspace.gDoor.caution.Transparency=(0.7)
            wait(0.9)
            isOpen = true
            workspace.gDoor.door.Transparency=(0)
            workspace.gDoor.door.CanCollide=true
            workspace.gDoor.window.CanCollide=true
            workspace.gDoor.caution.CanCollide=true
            workspace.gDoor.caution.Transparency=(0)
            isOpen = false  
        end
    end
end)

Try the script above, I am pretty sure it should work.

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