✓ Accepted answer
First of all, i will introduce you to FOR loops.
For loops are piece of code that repeats certain code for certain times... just look:
local StartValue =1
local GoalValue =10
local Increment = 1
for i = StartValue,GoalValue,Increment do
end
knowing that, you can make the doorFadeOpen() function less time-requiring, or something like that:
local StartValue =1
local GoalValue =9
local Increment = 1
door.CanCollide = false
for i = StartValue,GoalValue,Increment do
wait(0.1)
door.Transparency = (i/10)
end
wait(1)
door.Transparency = 0
door.CanCollide = true
so, we will put that to the script!
local door = script.Parent
function doorFadeOpen()
door.CanCollide = false
for i = 1,10 do
wait(0.1)
door.Transparency = (i/10)
end
wait(2)
door.Transparency = 0
door.CanCollide = true
end
But wait... theres something wrong here... A localplayer cant be set in a server script!
local function onPartTouch(otherPart)
local partParent = otherPart.Parent
local key = game.Players.LocalPlayer.BackPack.Key
if key then
door.CanCollide = false
doorFadeOpen()
door.CanCollide = true
end
end
door.Touched:Connect(onPartTouch)
So, we do this:
local function onPartTouch(otherPart)
local partParent = otherPart.Parent
local player = game.Players:GetPlayerFromCharacter(partParent)
if player then
' local key = partParent:FindFirstChild("Key") --checks if key is on the character (character holding it)
if key then --if the key exists then
doorFadeOpen() --open da door!
end
end
end
door.Touched:Connect(onPartTouch)
I hope that helped! p.s. i take more time explaining than writing code itself :/ does that mean im a good scriptinghelpers user??
1 comment
I can only ost an answer every 1.5 minutes but ill try to help you soon