Was wondering if I need to change anything or is it perfect? its for a rpg game
Here is the script:
function getPlayer(humanoid) local players = game.Players:children() for i = 1, #players do if players[i].Character.Humanoid == humanoid then return players[i] end end end
lvl = script.Parent.Parent.DoorSettings.Lvl.Value time = script.Parent.Parent.DoorSettings.OpenTime.Value
Door = script.Parent function onTouched(hit) print("Door Hit") local human = hit.Parent:findFirstChild("Humanoid") if (human ~= nil ) then
print("Human touched door") local player = getPlayer(human)
if (player == nil) then return end local stats = player:findFirstChild("leaderstats") local sp = stats:findFirstChild("Lvl") if sp == nil then return false end if (sp.Value >= lvl) then print("Human passed test") Door.Transparency = 1 Door.CanCollide = false wait(time) Door.CanCollide = true Door.Transparency = 0.5 else human.Health = human.Health end end
end
connection = Door.Touched:connect(onTouched)
Is there a weld on the door?
Try using that:
function getPlayer(humanoid) local players = game.Players:GetChildren() for i = 1, #players do if players[i].Character.Name == humanoid.Name then return players[i] end end end local lvl = script.Parent.Parent.DoorSettings.Lvl.Value local time = script.Parent.Parent.DoorSettings.OpenTime.Value Door = script.Parent function onTouched(hit) print("Door Hit") local human = hit.Parent:findFirstChild("Humanoid") if (human ~= nil ) then print("Human touched door") local player = getPlayer(human) if (player == nil) then return 0 -- For sure end local stats = player:findFirstChild("leaderstats") local sp = stats:findFirstChild("Lvl") if sp == nil then return 0 -- For sure end if (sp.Value >= lvl) then print("Human passed test") Door.Transparency = 1 Door.CanCollide = false wait(time) Door.CanCollide = true Door.Transparency = 0.5 end end end connection = Door.Touched:connect(onTouched)