I have a problem with my door script which randomly generates a number which will be the speed of the tween. I can’t find the reason why this script doesn’t work as there are no errors in the dev console.
local TweenService = game:GetService("TweenService")
local door = script.Parent
local doorHinge = door.PrimaryPart
local randomSpeed = Random.new()
local speed = randomSpeed:NextNumber(0.5, 1.2)
local doorOpen = TweenInfo.new(
speed,
Enum.EasingStyle.Linear
)
local doorCFrame = TweenService:Create(doorHinge, doorOpen, {
CFrame = doorHinge.CFrame * CFrame.Angles(0, math.rad(-100),0)--Change 100 to whatever value. Range of swing.
})
local ProximityPrompt = script.Parent.ProximityPrompt
local room = require(game.ServerScriptService.Server.Generation)
ProximityPrompt.Triggered:Connect(function()
script.Parent.part.Open.PlaybackSpeed = speed --open sound
doorCFrame:Play()
ProximityPrompt.Enabled = false
script.Parent.part.Open:Play()
end)
And what is the issue??? By the way, the random speed is chosen at the very beginning of the script and it will be never chosen again, this is because the script doesn’t run again.
I suggest wrapping the speed variable and the tweening lines inside a function so whenever the function is called, a random speed will be chosen once again.
Or you can as well, not make speed a variable. Just define the PlaybackSpeed as the math.random.
Is the doorHinge mentioned in the script welded to any other parts? I had an issue like this before where the script had no errors, but the part didn’t move due to welds. If you do, make sure they are welded correctly and unanchored - but the part being tweened is anchored.
P.S. I am a beginner so I would appreciate it if you could include a detailed explanation of how to fix it.
Thanks,
Jameson
This might not work, but it’s a good starting point for you. local TweenService = game:GetService(“TweenService”)
local door = script.Parent
local doorHinge = door.PrimaryPart
local randomSpeed = Random.new()
local speed = randomSpeed:NextNumber(0.5, 1.2)
local doorOpen = TweenInfo.new(
speed,
Enum.EasingStyle.Linear
)
local doorCFrame = TweenService:Create(doorHinge, doorOpen, {
CFrame = doorHinge.CFrame * CFrame.Angles(0, math.rad(-100),0)–Change 100 to whatever value. Range of swing.
})
local ProximityPrompt = script.Parent.ProximityPrompt
local room = require(game.ServerScriptService.Server.Generation)