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

door dosent open on hit function with humanoid ,how to fix it?

so i making a house door system with string value and there is the script

local name = workspace.test.teSTO.name.Value
local plr = game.Players.LocalPlayer
script.Parent.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid then
		if plr.Name == name.Value then
				script.Parent.CanCollide = false 
				script.Parent.Transparency = 0.7 
				wait(1.4) 
				script.Parent.CanCollide = true 
				script.Parent.Transparency = 0 
		end
	end
end)

but i get this error

Workspace.door.Script:6: attempt to index nil with 'Name'  -  Server  -  Script:6

how can i fix it

1 answer

✓ Accepted answer

The reason why this error is occurring is because you are not getting the player properly. Try this:

local name = workspace.test.teSTO.name.Value
-- I removed the local player line since you can't get the local player like that through a script.
script.Parent.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid then
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent) -- This is the new line. Add this.
        if plr.Name == name.Value then
                script.Parent.CanCollide = false 
                script.Parent.Transparency = 0.7 
                wait(1.4) 
                script.Parent.CanCollide = true 
                script.Parent.Transparency = 0 
        end
    end
end)

Hope this helps.

2 comments

0

sadly isnt working.. https://imgur.com/a/MgjP36Q

0

Well, your question was about the error. That is removed. It isn't showing the error anymore.

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