Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

Am i Makeing This Door Script Correctly?

Asked by
ssadak 0
8 years ago

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)

2 answers

Log in to vote
0
Answered by 8 years ago

Is there a weld on the door?

0
That's not an answer xD advisterment 0 — 8y
0
its a door level requirement script to go threw the door ssadak 0 — 8y
0
that is confusing ssadak 0 — 8y
0
So is there supposed to be an opening animation? advisterment 0 — 8y
0
You can just use a simple weld. advisterment 0 — 8y
Ad
Log in to vote
0
Answered by
Etheroit 178
8 years ago

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)

Answer this question