instruction stringclasses 1
value | input stringclasses 8
values | output stringlengths 50 15k |
|---|---|---|
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local function visiblearms(bool)
if armsvisible then
local castshadow = not bool
for i, part in ipairs(armparts) do
part.LocalTransparencyModifier = armtransparency
part.CanCollide = false
part.CastShadow = castshadow
end
end
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | function scriptChildModified(child)
local fileList = animNames[child.Name]
if (fileList ~= nil) then
configureAnimationSet(child.Name, fileList)
end
end
script.ChildAdded:connect(scriptChildModified)
script.ChildRemoved:connect(scriptChildModified)
for name, fileList in pairs(animNames) do
configureAnimationSet(name, fileList)
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local Drive={}
--Power Front Wheels
if _Tune.Config == "FWD" or _Tune.Config == "AWD" then
for i,v in pairs(car.Wheels:GetChildren()) do
if v.Name=="FL" or v.Name=="FR" or v.Name=="F" then
table.insert(Drive,v)
end
end
end
--Power Rear Wheels
if _Tune.Config == "RWD" or _Tune.Config == "AWD" then
for i,v in pairs(car.Wheels:GetChildren()) do
if v.Name=="RL" or v.Name=="RR" or v.Name=="R" then
table.insert(Drive,v)
end
end
end
--Determine Wheel Size
local wDia = 0
for i,v in pairs(Drive) do
if v.Size.x>wDia then wDia = v.Size.x end
end
--Pre-Toggled PBrake
for i,v in pairs(car.Wheels:GetChildren()) do
if v["#AV"]:IsA("BodyAngularVelocity") then
if math.abs(v["#AV"].maxTorque.Magnitude-PBrakeForce)<1 then
_PBrake=true
end
else
if math.abs(v["#AV"].MotorMaxTorque-PBrakeForce)<1 then
_PBrake=true
end
end
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local ClientBridge = require(script.ClientBridge)
local ClientIdentifiers = require(script.ClientIdentifiers)
local ClientProcess = require(script.ClientProcess)
local Types = require(script.Parent.Types)
local Client = {}
function Client.start()
ClientProcess.start()
ClientIdentifiers.start()
end
function Client.ser(identifierName: Types.Identifier): Types.Identifier?
return ClientIdentifiers.ser(identifierName)
end
function Client.deser(compressedIdentifier: Types.Identifier): Types.Identifier?
return ClientIdentifiers.deser(compressedIdentifier)
end
function Client.makeIdentifier(name: string, timeout: number?)
return ClientIdentifiers.ref(name, timeout)
end
function Client.makeBridge(name: string)
return ClientBridge(name)
end
return Client |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | function Flip()
--Detect Orientation
if (car.DriveSeat.CFrame*CFrame.Angles(math.pi/2,0,0)).lookVector.y > .1 or FlipDB then
FlipWait=tick()
--Apply Flip
else
if tick()-FlipWait>=3 then
FlipDB=true
local gyro = car.DriveSeat.Flip
gyro.maxTorque = Vector3.new(10000,0,10000)
gyro.P=3000
gyro.D=500
wait(1)
gyro.maxTorque = Vector3.new(0,0,0)
gyro.P=0
gyro.D=0
FlipDB=false
end
end
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | --
function Path:Destroy()
for _, event in ipairs(self._events) do
event:Destroy()
end
self._events = nil
if rawget(self, "_visualWaypoints") then
self._visualWaypoints = destroyVisualWaypoints(self._visualWaypoints)
end
self._path:Destroy()
setmetatable(self, nil)
for k, _ in pairs(self) do
self[k] = nil
end
end
function Path:Stop()
if not self._humanoid then
output(error, "Attempt to call Path:Stop() on a non-humanoid.")
return
end
if self._status == Path.StatusType.Idle then
output(function(m)
warn(debug.traceback(m))
end, "Attempt to run Path:Stop() in idle state")
return
end
disconnectMoveConnection(self)
self._status = Path.StatusType.Idle
self._visualWaypoints = destroyVisualWaypoints(self._visualWaypoints)
self._events.Stopped:Fire(self._model)
end
function Path:Run(target)
--Non-humanoid handle case
if not target and not self._humanoid and self._target then
moveToFinished(self, true)
return
end
--Parameter check
if not (target and (typeof(target) == "Vector3" or target:IsA("BasePart"))) then
output(error, "Pathfinding target must be a valid Vector3 or BasePart.")
end
--Refer to Settings.TIME_VARIANCE
if os.clock() - self._t <= self._settings.TIME_VARIANCE and self._humanoid then
task.wait(os.clock() - self._t)
declareError(self, self.ErrorType.LimitReached)
return false
elseif self._humanoid then
self._t = os.clock()
end
--Compute path
local pathComputed, _ = pcall(function()
self._path:ComputeAsync(self._agent.PrimaryPart.Position, (typeof(target) == "Vector3" and target) or target.Position)
end)
--Make sure path computation is successful
if not pathComputed
or self._path.Status == Enum.PathStatus.NoPath
or #self._path:GetWaypoints() < 2
or (self._humanoid and self._humanoid:GetState() == Enum.HumanoidStateType.Freefall) then
self._visualWaypoints = destroyVisualWaypoints(self._visualWaypoints)
task.wait()
declareError(self, self.ErrorType.ComputationError)
return false
end
--Set status to active; pathfinding starts
self._status = (self._humanoid and Path.StatusType.Active) or Path.StatusType.Idle
self._target = target
--Set network owner to server to prevent "hops"
pcall(function()
self._agent.PrimaryPart:SetNetworkOwner(nil)
end)
--Initialize waypoints
self._waypoints = self._path:GetWaypoints()
self._currentWaypoint = 2
--Refer to Settings.COMPARISON_CHECKS
if self._humanoid then
comparePosition(self)
end
--Visualize waypoints
destroyVisualWaypoints(self._visualWaypoints)
self._visualWaypoints = (self.Visualize and createVisualWaypoints(self._waypoints))
--Create a new move connection if it doesn't exist already
self._moveConnection = self._humanoid and (self._moveConnection or self._humanoid.MoveToFinished:Connect(function(...)
moveToFinished(self, ...)
end))
--Begin pathfinding
if self._humanoid then
self._humanoid:MoveTo(self._waypoints[self._currentWaypoint].Position)
elseif #self._waypoints == 2 then
self._target = nil
self._visualWaypoints = destroyVisualWaypoints(self._visualWaypoints)
self._events.Reached:Fire(self._agent, self._waypoints[2])
else
self._currentWaypoint = getNonHumanoidWaypoint(self)
moveToFinished(self, true)
end
return true
end
return Path |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local function Steering()
local SteerLocal = script.Parent.Values.SteerC.Value
--Mouse Steer
if _MSteer then
local msWidth = math.max(1,mouse.ViewSizeX*_Tune.Peripherals.MSteerWidth/200)
local mdZone = _Tune.Peripherals.MSteerDZone/100
local mST = ((mouse.X-mouse.ViewSizeX/2)/msWidth)
if math.abs(mST)<=mdZone then
_GSteerT = 0
else
_GSteerT = (math.max(math.min((math.abs(mST)-mdZone),(1-mdZone)),0)/(1-mdZone))^_Tune.MSteerExp * (mST / math.abs(mST))
end
end
--Interpolate Steering
if SteerLocal < _GSteerT then
if SteerLocal<0 then
SteerLocal = math.min(_GSteerT,SteerLocal+_Tune.ReturnSpeed)
else
SteerLocal = math.min(_GSteerT,SteerLocal+_Tune.SteerSpeed)
end
else
if SteerLocal>0 then
SteerLocal = math.max(_GSteerT,SteerLocal-_Tune.ReturnSpeed)
else
SteerLocal = math.max(_GSteerT,SteerLocal-_Tune.SteerSpeed)
end
end
--Steer Decay Multiplier
local sDecay = (1-math.min(car.DriveSeat.Velocity.Magnitude/_Tune.SteerDecay,1-(_Tune.MinSteer/100)))
--Apply Steering
for _,v in ipairs(car.Wheels:GetChildren()) do
if v.Name=="F" then
v.Arm.Steer.CFrame=car.Wheels.F.Base.CFrame*CFrame.Angles(0,-math.rad(SteerLocal*_Tune.SteerInner*sDecay),0)
elseif v.Name=="FL" then
if SteerLocal>= 0 then
v.Arm.Steer.CFrame=car.Wheels.FL.Base.CFrame*CFrame.Angles(0,-math.rad(SteerLocal*_Tune.SteerOuter*sDecay),0)
else
v.Arm.Steer.CFrame=car.Wheels.FL.Base.CFrame*CFrame.Angles(0,-math.rad(SteerLocal*_Tune.SteerInner*sDecay),0)
end
elseif v.Name=="FR" then
if SteerLocal>= 0 then
v.Arm.Steer.CFrame=car.Wheels.FR.Base.CFrame*CFrame.Angles(0,-math.rad(SteerLocal*_Tune.SteerInner*sDecay),0)
else
v.Arm.Steer.CFrame=car.Wheels.FR.Base.CFrame*CFrame.Angles(0,-math.rad(SteerLocal*_Tune.SteerOuter*sDecay),0)
end
end
end
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | function Prone()
L_87_:FireServer("Prone")
L_14_:Create(L_3_:WaitForChild('Humanoid'), TweenInfo.new(0.3), {
CameraOffset = Vector3.new(0, -3, 0)
}):Play()
L_3_:WaitForChild("Humanoid").WalkSpeed = 4
L_127_ = 4
L_126_ = 0.025
L_47_ = true
L_67_ = 0.01
L_66_ = -0.05
L_68_ = 0.05
Proned2 = Vector3.new(0, 0.5, 0.5)
L_102_(L_9_, CFrame.new(0, -2.4201169, -0.0385534465, -0.99999994, -5.86197757e-012, -4.54747351e-013, 5.52669195e-012, 0.998915195, 0.0465667509, 0, 0.0465667509, -0.998915195), nil, function(L_249_arg1)
return math.sin(math.rad(L_249_arg1))
end, 0.25)
L_102_(L_10_, CFrame.new(1.00000191, -1, -5.96046448e-008, 1.31237243e-011, -0.344507754, 0.938783348, 0, 0.938783467, 0.344507784, -1, 0, -1.86264515e-009) , nil, function(L_250_arg1)
return math.sin(math.rad(L_250_arg1))
end, 0.25)
L_102_(L_11_, CFrame.new(-0.999996185, -1, -1.1920929e-007, -2.58566502e-011, 0.314521015, -0.949250221, 0, 0.94925046, 0.314521164, 1, 3.7252903e-009, 1.86264515e-009) , nil, function(L_251_arg1)
return math.sin(math.rad(L_251_arg1))
end, 0.25)
end
function Stand()
L_87_:FireServer("Stand")
L_14_:Create(L_3_:WaitForChild('Humanoid'), TweenInfo.new(0.3), {
CameraOffset = Vector3.new(0, 0, 0)
}):Play()
L_47_ = false
if not L_46_ then
L_3_:WaitForChild("Humanoid").WalkSpeed = 16
L_126_ = .2
L_127_ = 17
L_67_ = L_23_.camrecoil
L_66_ = L_23_.gunrecoil
L_68_ = L_23_.Kickback
elseif L_46_ then
L_3_:WaitForChild("Humanoid").WalkSpeed = 16
L_127_ = 10
L_126_ = 0.02
L_67_ = L_23_.AimCamRecoil
L_66_ = L_23_.AimGunRecoil
L_68_ = L_23_.AimKickback
end
Proned2 = Vector3.new(0, 0, 0)
L_102_(L_9_, CFrame.new(0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 1, -0), nil, function(L_252_arg1)
return math.sin(math.rad(L_252_arg1))
end, 0.25)
L_102_(L_10_, CFrame.new(1, -1, 0, 0, 0, 1, 0, 1, -0, -1, 0, 0), nil, function(L_253_arg1)
return math.sin(math.rad(L_253_arg1))
end, 0.25)
L_102_(L_11_, CFrame.new(-1, -1, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0), nil, function(L_254_arg1)
return math.sin(math.rad(L_254_arg1))
end, 0.25)
end
function Crouch()
L_87_:FireServer("Crouch")
L_14_:Create(L_3_:WaitForChild('Humanoid'), TweenInfo.new(0.3), {
CameraOffset = Vector3.new(0, -1, 0)
}):Play()
L_3_:WaitForChild("Humanoid").WalkSpeed = 9
L_127_ = 9
L_126_ = 0.035
L_47_ = true
L_67_ = 0.02
L_66_ = -0.05
L_68_ = 0.05
Proned2 = Vector3.new(0, 0, 0)
L_102_(L_9_, CFrame.new(0, -1.04933882, 0, -1, 0, -1.88871293e-012, 1.88871293e-012, -3.55271368e-015, 1, 0, 1, -3.55271368e-015), nil, function(L_255_arg1)
return math.sin(math.rad(L_255_arg1))
end, 0.25)
L_102_(L_10_, CFrame.new(1, 0.0456044674, -0.494239986, 6.82121026e-013, -1.22639676e-011, 1, -0.058873821, 0.998265445, -1.09836602e-011, -0.998265445, -0.058873821, 0), nil, function(L_256_arg1)
return math.sin(math.rad(L_256_arg1))
end, 0.25)
L_102_(L_11_, CFrame.new(-1.00000381, -0.157019258, -0.471293032, -8.7538865e-012, -8.7538865e-012, -1, 0.721672177, 0.692235112, 1.64406284e-011, 0.692235112, -0.721672177, 0), nil, function(L_257_arg1)
return math.sin(math.rad(L_257_arg1))
end, 0.25)
L_102_(L_6_:WaitForChild("Neck"), nil, CFrame.new(0, -0.5, 0, -1, 0, 0, 0, 0, 1, 0, 1, -0), function(L_258_arg1)
return math.sin(math.rad(L_258_arg1))
end, 0.25)
end
local L_137_ = false
L_82_.InputBegan:connect(function(L_259_arg1, L_260_arg2)
if not L_260_arg2 and L_15_ == true then
if L_15_ then
if L_259_arg1.KeyCode == Enum.KeyCode.C then
if L_70_ == 0 and not L_49_ and L_15_ then
L_70_ = 1
Crouch()
L_71_ = false
L_73_ = true
L_72_ = false
elseif L_70_ == 1 and not L_49_ and L_15_ then
L_70_ = 2
Prone()
L_73_ = false
L_71_ = true
L_72_ = false
L_137_ = true
end
end
if L_259_arg1.KeyCode == Enum.KeyCode.X then
if L_70_ == 2 and not L_49_ and L_15_ then
L_137_ = false
L_70_ = 1
Crouch()
L_71_ = false
L_73_ = true
L_72_ = false
elseif L_70_ == 1 and not L_49_ and L_15_ then
L_70_ = 0
Stand()
L_71_ = false
L_73_ = false
L_72_ = true
end
end
end
end
end) |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local engineStartTween = TweenInfo.new(0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0, false, 0)
local Remotes = Vehicle:WaitForChild("Remotes")
local SetThrottleRemote = Remotes:WaitForChild("SetThrottle")
local SetThrottleConnection = nil
local EngineSoundEnabled = true
local TireTrailEnabled = true
local ignitionTime = 1.75 -- seconds
local lastAvgAngularVelocity = 0
local throttleEnabled = false
local lastThrottleUpdate = 0
local enginePower = 0 -- current rpm of the engine
local gainModifier = 1 -- modifier to engine rpm gain (lower if approaching max speed) |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local function WaitForChild(parent, childName)
while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end
return parent[childName]
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local e=2.718281828459045
local function posvel(d,s,p0,v0,p1,v1,x)
if s==0 then
return p0
elseif d<1-1e-8 then
local h=(1-d*d)^0.5
local c1=(p0-p1+2*d/s*v1)
local c2=d/h*(p0-p1)+v0/(h*s)+(2*d*d-1)/(h*s)*v1
local co=math.cos(h*s*x)
local si=math.sin(h*s*x)
local ex=e^(d*s*x)
return co/ex*c1+si/ex*c2+p1+(x-2*d/s)*v1, s*(co*h-d*si)/ex*c2-s*(co*d+h*si)/ex*c1+v1
elseif d<1+1e-8 then
local c1=p0-p1+2/s*v1
local c2=p0-p1+(v0+v1)/s
local ex=e^(s*x)
return (c1+c2*s*x)/ex+p1+(x-2/s)*v1, v1-s/ex*(c1+(s*x-1)*c2)
else
local h=(d*d-1)^0.5
local a=(v1-v0)/(2*s*h)
local b=d/s*v1-(p1-p0)/2
local c1=(1-d/h)*b+a
local c2=(1+d/h)*b-a
local co=e^(-(h+d)*s*x)
local si=e^((h-d)*s*x)
return c1*co+c2*si+p1+(x-2*d/s)*v1, si*(h-d)*s*c2-co*(d+h)*s*c1+v1
end
end
local function targposvel(p1,v1,x)
return p1+x*v1,v1
end
local Spring = {}
Spring.__index = Spring |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local ratio = 6.1/#themeColors
local themeFrame = pages.custom["AB ThemeSelection"]
local themeDe = true
local function updateThemeSelection(themeName, themeColor)
if themeName == nil then
for i,v in pairs(themeColors) do
if v[1] == main.pdata.Theme then
themeName = v[1]
themeColor = v[2]
break
end
end
end
if themeName then
local themeFrames = {}
for a,b in pairs(main.gui:GetDescendants()) do
if b:IsA("BoolValue") and b.Name == "Theme" then
table.insert(themeFrames, b.Parent)
end
end
for _,f in pairs(themeFrames) do
local newThemeColor = themeColor
if f.Theme.Value then
local h,s,v = Color3.toHSV(themeColor)
newThemeColor = Color3.fromHSV(h, s, v*1.35)
end
if f:IsA("TextLabel") then
local h,s,v = Color3.toHSV(themeColor)
newThemeColor = Color3.fromHSV(h, s, v*2)
f.TextColor3 = newThemeColor
else
f.BackgroundColor3 = newThemeColor
end
end
for a,b in pairs(themeFrame:GetChildren()) do
if b:IsA("TextButton") then
if b.Name == themeName then
b.BorderSizePixel = 1
else
b.BorderSizePixel = 0
end
end
end
end
end
for i, theme in pairs(themeColors) do
local themeName = theme[1]
local themeColor = theme[2]
local box = themeFrame.ThemeTemplate:Clone()
box.Name = themeName
box.UIAspectRatioConstraint.AspectRatio = ratio
box.BackgroundColor3 = themeColor
box.MouseButton1Down:Connect(function()
if themeDe then
themeDe = false
main.signals.ChangeSetting:InvokeServer{"Theme", themeName}
updateThemeSelection(themeName, themeColor)
themeDe = true
end
end)
box.Visible = true
box.Parent = themeFrame
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | function wait_time(duration)
local start = tick()
local Heartbeat = game:GetService("RunService").Heartbeat
repeat Heartbeat:Wait() until (tick() - start) >= duration
return (tick() - start)
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local DataStoreService = game:GetService("DataStoreService")
local OrderedBackups = {}
OrderedBackups.__index = OrderedBackups
function OrderedBackups:Get()
local success, value = pcall(function()
return self.orderedDataStore:GetSortedAsync(false, 1):GetCurrentPage()[1]
end)
if not success then
return false, value
end
if value then
local mostRecentKeyPage = value
local recentKey = mostRecentKeyPage.value
self.dataStore2:Debug("most recent key", mostRecentKeyPage)
self.mostRecentKey = recentKey
local success, value = pcall(function()
return self.dataStore:GetAsync(recentKey)
end)
if not success then
return false, value
end
return true, value
else
self.dataStore2:Debug("no recent key")
return true, nil
end
end
function OrderedBackups:Set(value)
local key = (self.mostRecentKey or 0) + 1
local success, problem = pcall(function()
self.dataStore:SetAsync(key, value)
end)
if not success then
return false, problem
end
local success, problem = pcall(function()
self.orderedDataStore:SetAsync(key, key)
end)
if not success then
return false, problem
end
self.mostRecentKey = key
return true
end
function OrderedBackups.new(dataStore2)
local dataStoreKey = dataStore2.Name .. "/" .. dataStore2.UserId
local info = {
dataStore2 = dataStore2,
dataStore = DataStoreService:GetDataStore(dataStoreKey),
orderedDataStore = DataStoreService:GetOrderedDataStore(dataStoreKey),
}
return setmetatable(info, OrderedBackups)
end
return OrderedBackups |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | This = script.Parent
Elevator = This.Parent.Parent.Parent
CustomLabel = require(This.Parent.Parent.Parent.CustomLabel)
Characters = require(script.Characters)
CustomText = CustomLabel["CUSTOMFLOORLABEL"]
Elevator:WaitForChild("Floor").Changed:connect(function(floor)
--custom indicator code--
ChangeFloor(tostring(floor))
end)
function ChangeFloor(SF)
if CustomText[tonumber(SF)] then
SF = CustomText[tonumber(SF)]
end
SetDisplay(1,(string.len(SF) == 2 and SF:sub(1,1) or "NIL"))
SetDisplay(2,(string.len(SF) == 2 and SF:sub(2,2) or SF))
end
function SetDisplay(ID,CHAR)
if This.Display:FindFirstChild("DIG"..ID) and Characters[CHAR] ~= nil then
for i,l in pairs(Characters[CHAR]) do
for r=1,7 do
This.Display["DIG"..ID]["D"..r].Color = (l:sub(r,r) == "1" and DisplayColor or DisabledColor)
This.Display["DIG"..ID]["D"..r].Material = (l:sub(r,r) == "1" and Lit or Unlit)
end
end
end
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | function keyDown(K)
local Key = string.lower(K)
if Key == S.Keys.lowerStance and S.canChangeStance then
if (not Running) then
if Stance == 0 then
if S.stanceSettings.Stances.Crouch then
Crouch()
elseif S.stanceSettings.Stances.Prone then
Prone()
end
elseif Stance == 1 then
if S.stanceSettings.Stances.Prone then
Prone()
end
end
elseif S.dolphinDive then
wait()
if Humanoid:GetState() ~= Enum.HumanoidStateType.Freefall and (not UIS:IsKeyDown("Space")) and runReady then
local tempConnection = Humanoid.Changed:connect(function()
Humanoid.Jump = false
end)
runReady = false
Dive()
Running = false
wait(S.diveSettings.rechargeTime)
tempConnection:disconnect()
runReady = true
end
end
end
if Key == S.Keys.raiseStance and S.canChangeStance then
if (not Running) then
if Stance == 2 then
if S.stanceSettings.Stances.Crouch then
Crouch()
else
Stand()
end
elseif Stance == 1 then
Stand()
end
end
end
if Key == S.Keys.ADS then
if S.aimSettings.holdToADS then
if (not AimingIn) and (not Aimed) then
AimingIn = true
aimGun()
AimingIn = false
end
else
if Aimed then
unAimGun()
else
aimGun()
end
end
end
if Key == S.Keys.selectFire and S.selectFire then
if canSelectFire then
canSelectFire = false
rawFireMode = rawFireMode + 1
modeGUI.Text = Modes[((rawFireMode - 1) % numModes) + 1]
if modeGUI.Text == "AUTO" then
fireFunction = autoFire
elseif modeGUI.Text == "BURST" then
fireFunction = burstFire
elseif modeGUI.Text == "SEMI" then
fireFunction = semiFire
else
fireFunction = nil
end
local speedAlpha = S.selectFireSettings.animSpeed / 0.6
if S.selectFireSettings.GUI then
spawn(function()
fireSelect.Visible = true
local prevRawFireMode = rawFireMode
local Increment = 1.5 / (speedAlpha * 0.25)
local X = 0
wait(speedAlpha * 0.1)
while true do
RS.RenderStepped:wait()
local newX = X + Increment
X = (newX > 90 and 90 or newX)
if prevRawFireMode ~= rawFireMode then break end
updateModeLabels(rawFireMode - 1, rawFireMode, X)
if X == 90 then break end
end
wait(speedAlpha * 0.25)
fireSelect.Visible = false
end)
end
if S.selectFireSettings.Animation and (not Aimed) and (not isRunning) and (not isCrawling) then
spawn(function()
local sequenceTable = {
function()
tweenJoint(RWeld2, nil, CFANG(0, RAD(5), 0), Sine, speedAlpha * 0.15)
tweenJoint(LWeld, armC0[1], CF(0.1, 1, -0.3) * CFANG(RAD(-7), 0, RAD(-65)), Linear, speedAlpha * 0.15)
wait(speedAlpha * 0.2)
end;
function()
tweenJoint(LWeld, armC0[1], CF(0.1, 1, -0.3) * CFANG(RAD(-10), 0, RAD(-65)), Linear, speedAlpha * 0.1)
wait(speedAlpha * 0.2)
end;
function()
tweenJoint(RWeld2, nil, CF(), Sine, speedAlpha * 0.2)
tweenJoint(LWeld, armC0[1], S.unAimedC1.leftArm, Sine, speedAlpha * 0.2)
wait(speedAlpha * 0.2)
end;
}
for _, F in pairs(sequenceTable) do
if Aimed or isRunning or isCrawling or Reloading then
break
end
F()
end
end)
end
if S.selectFireSettings.Animation or S.selectFireSettings.GUI then
wait(S.selectFireSettings.animSpeed)
end
canSelectFire = true
end
end
if Key == S.Keys.Reload then
if (not Reloading) and (not isCrawling) then
Reload()
end
end
if Key == S.Keys.Sprint then
runKeyPressed = true
if runReady then
if (not Idling) and Walking and (not Running) and (not Knifing) and (not (Aimed and S.guiScope and S.Keys.Sprint == S.Keys.scopeSteady)) then
monitorStamina()
end
end
end
if Key == S.Keys.scopeSteady then
steadyKeyPressed = true
if Aimed and (not Aiming) then
takingBreath = false
steadyCamera()
end
end
for _, PTable in pairs(Plugins.KeyDown) do
if Key == string.lower(PTable.Key) then
spawn(function()
PTable.Plugin()
end)
end
end
end
function keyUp(K)
local Key = string.lower(K)
if Key == S.Keys.ADS then
if S.aimSettings.holdToADS then
if (not AimingOut) and Aimed then
AimingOut = true
unAimGun()
AimingOut = false
end
end
end
if Key == S.Keys.Sprint then
runKeyPressed = false
Running = false
if (not chargingStamina) then
rechargeStamina()
end
end
if Key == S.Keys.scopeSteady then
steadyKeyPressed = false
end
for _, PTable in pairs(Plugins.KeyUp) do
if Key == string.lower(PTable.Key) then
spawn(function()
PTable.Plugin()
end)
end
end
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local function ApplyTags(target)
while target:FindFirstChild('creator') do
target.creator:Destroy()
end
local creatorTagClone = CreatorTag:Clone()
DebrisService:AddItem(creatorTagClone, 1.5)
creatorTagClone.Parent = target
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | function UnDigify(digit)
if digit < 1 or digit > 61 then
return ""
elseif digit == 1 then
return "1"
elseif digit == 2 then
return "!"
elseif digit == 3 then
return "2"
elseif digit == 4 then
return "@"
elseif digit == 5 then
return "3"
elseif digit == 6 then
return "4"
elseif digit == 7 then
return "$"
elseif digit == 8 then
return "5"
elseif digit == 9 then
return "%"
elseif digit == 10 then
return "6"
elseif digit == 11 then
return "^"
elseif digit == 12 then
return "7"
elseif digit == 13 then
return "8"
elseif digit == 14 then
return "*"
elseif digit == 15 then
return "9"
elseif digit == 16 then
return "("
elseif digit == 17 then
return "0"
elseif digit == 18 then
return "q"
elseif digit == 19 then
return "Q"
elseif digit == 20 then
return "w"
elseif digit == 21 then
return "W"
elseif digit == 22 then
return "e"
elseif digit == 23 then
return "E"
elseif digit == 24 then
return "r"
elseif digit == 25 then
return "t"
elseif digit == 26 then
return "T"
elseif digit == 27 then
return "y"
elseif digit == 28 then
return "Y"
elseif digit == 29 then
return "u"
elseif digit == 30 then
return "i"
elseif digit == 31 then
return "I"
elseif digit == 32 then
return "o"
elseif digit == 33 then
return "O"
elseif digit == 34 then
return "p"
elseif digit == 35 then
return "P"
elseif digit == 36 then
return "a"
elseif digit == 37 then
return "s"
elseif digit == 38 then
return "S"
elseif digit == 39 then
return "d"
elseif digit == 40 then
return "D"
elseif digit == 41 then
return "f"
elseif digit == 42 then
return "g"
elseif digit == 43 then
return "G"
elseif digit == 44 then
return "h"
elseif digit == 45 then
return "H"
elseif digit == 46 then
return "j"
elseif digit == 47 then
return "J"
elseif digit == 48 then
return "k"
elseif digit == 49 then
return "l"
elseif digit == 50 then
return "L"
elseif digit == 51 then
return "z"
elseif digit == 52 then
return "Z"
elseif digit == 53 then
return "x"
elseif digit == 54 then
return "c"
elseif digit == 55 then
return "C"
elseif digit == 56 then
return "v"
elseif digit == 57 then
return "V"
elseif digit == 58 then
return "b"
elseif digit == 59 then
return "B"
elseif digit == 60 then
return "n"
elseif digit == 61 then
return "m"
else
return "?"
end
end
function IsBlack(note)
if note%12 == 2 or note%12 == 4 or note%12 == 7 or note%12 == 9 or note%12 == 11 then
return true
end
end
local TweenService = game:GetService("TweenService")
function Tween(obj,Goal,Time,Wait,...) local TwInfo = TweenInfo.new(Time,...) local twn = TweenService:Create(obj, TwInfo, Goal) twn:Play() if Wait then twn.Completed:wait() end return
end
local orgins = {} if script.Parent.Keys:FindFirstChild("Keys") then for i,v in pairs(script.Parent.Keys.Keys:GetChildren()) do orgins[v.Name] = {v.Position,v.Orientation} end else for i,v in pairs(script.Parent.Keys:GetChildren()) do if v:IsA("Model") then for a,b in pairs(v:GetChildren()) do orgins[v.Name] = {b.Position,b.Orientation} end end end end function AnimateKey(note1,px,py,pz,ox,oy,oz,Time) pcall(function() local obj = script.Parent.Keys.Keys:FindFirstChild(note1) if obj then local Properties = {} local OrginP = orgins[obj.Name][1] local OrginO = orgins[obj.Name][2] local changep = OrginP - Vector3.new(px,py,pz) local changeo = OrginO - Vector3.new(ox,oy,oz) Properties.Position = Vector3.new(obj.Position.x, changep.Y, changep.Z) Properties.Orientation = changeo Tween(obj,Properties,Time,Enum.EasingStyle.Linear) Properties = {} Properties.Position = Vector3.new(obj.Position.x,OrginP.y,OrginP.z) Properties.Orientation = OrginO Tween(obj,Properties,Time,Enum.EasingStyle.Linear) else print(note1..' was not found, or you do not have the correct configuration for the piano keys') end end) end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | for _, drop in pairs(DROPS:GetChildren()) do
HandleDrop(drop)
end
local t = 0
RunService.Stepped:connect(function(_, deltaTime)
t = t + deltaTime
for drop, dropInfo in pairs(drops) do
local offset = drop.Position - CAMERA.CFrame.p
if math.abs(offset.X) < UPDATE_RANGE and math.abs(offset.Y) < UPDATE_RANGE and math.abs(offset.Z) < UPDATE_RANGE then
local localT = t + (drop.Position.X + drop.Position.Z) * 0.2
local cframe = CFrame.new(drop.Position) * CFrame.new(0, math.sin(localT) * 0.2, 0) * CFrame.Angles(0, localT / 4, 0)
for _, info in pairs(dropInfo.Parts) do
info.Part.CFrame = cframe * info.Offset
local offset = info.Part.Position - CAMERA.CFrame.p
info.Outline.CFrame = info.Part.CFrame + offset.Unit * OUTLINE_WIDTH * 2
end
end
end
end) |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local function getClientPlatform()
-- TODO: Get input, and return Keyboard, Controller, or Touch
return "Keyboard"
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local v1 = {
Died = 0,
Running = 1,
Swimming = 2,
Climbing = 3,
Jumping = 4,
GettingUp = 5,
FreeFalling = 6,
FallingDown = 7,
Landing = 8,
Splash = 9
};
local v2 = nil;
local v3 = {};
local l__ReplicatedStorage__4 = game:GetService("ReplicatedStorage");
local v5 = l__ReplicatedStorage__4:FindFirstChild("DefaultSoundEvents");
local v6 = UserSettings():IsUserFeatureEnabled("UserUseSoundDispatcher");
if v6 then
if not v5 then
v5 = Instance.new("Folder", l__ReplicatedStorage__4);
v5.Name = "DefaultSoundEvents";
v5.Archivable = false;
end;
local v7 = v5:FindFirstChild("RemoveCharacterEvent");
if v7 == nil then
v7 = Instance.new("RemoteEvent", v5);
v7.Name = "RemoveCharacterEvent";
end;
local v8 = v5:FindFirstChild("AddCharacterLoadedEvent");
if v8 == nil then
v8 = Instance.new("RemoteEvent", v5);
v8.Name = "AddCharacterLoadedEvent";
end;
v8:FireServer();
game.Players.LocalPlayer.CharacterRemoving:connect(function(p1)
v7:FireServer(game.Players.LocalPlayer);
end);
end;
local l__Parent__9 = script.Parent.Parent;
local l__Head__10 = l__Parent__9:WaitForChild("Head");
while not v2 do
for v11, v12 in pairs(l__Parent__9:GetChildren()) do
if v12:IsA("Humanoid") then
v2 = v12;
break;
end;
end;
if v2 then
break;
end;
l__Parent__9.ChildAdded:wait();
end;
v3[v1.Died] = l__Head__10:WaitForChild("Died");
v3[v1.Running] = l__Head__10:WaitForChild("Running");
v3[v1.Swimming] = l__Head__10:WaitForChild("Swimming");
v3[v1.Climbing] = l__Head__10:WaitForChild("Climbing");
v3[v1.Jumping] = l__Head__10:WaitForChild("Jumping");
v3[v1.GettingUp] = l__Head__10:WaitForChild("GettingUp");
v3[v1.FreeFalling] = l__Head__10:WaitForChild("FreeFalling");
v3[v1.Landing] = l__Head__10:WaitForChild("Landing");
v3[v1.Splash] = l__Head__10:WaitForChild("Splash");
if v6 then
local v13 = v5:FindFirstChild("DefaultServerSoundEvent");
else
v13 = game:GetService("ReplicatedStorage"):FindFirstChild("DefaultServerSoundEvent");
end;
if v13 then
v13.OnClientEvent:connect(function(p2, p3, p4)
if p4 and p2.TimePosition ~= 0 then
p2.TimePosition = 0;
end;
if p2.IsPlaying ~= p3 then
p2.Playing = p3;
end;
end);
end;
local l__SoundService__1 = game:GetService("SoundService");
local v14 = {
YForLineGivenXAndTwoPts = function(p5, p6, p7, p8, p9)
local v15 = (p7 - p9) / (p6 - p8);
return v15 * p5 + (p7 - v15 * p6);
end,
Clamp = function(p10, p11, p12)
return math.min(p12, math.max(p11, p10));
end,
HorizontalSpeed = function(p13)
return (p13.Velocity + Vector3.new(0, -p13.Velocity.Y, 0)).magnitude;
end,
VerticalSpeed = function(p14)
return math.abs(p14.Velocity.Y);
end
};
local function u2()
return game.Workspace.FilteringEnabled and l__SoundService__1.RespectFilteringEnabled;
end;
function v14.Play(p15)
if u2() then
p15.CharacterSoundEvent:FireServer(true, true);
end;
if p15.TimePosition ~= 0 then
p15.TimePosition = 0;
end;
if not p15.IsPlaying then
p15.Playing = true;
end;
end;
function v14.Pause(p16)
if u2() then
p16.CharacterSoundEvent:FireServer(false, false);
end;
if p16.IsPlaying then
p16.Playing = false;
end;
end;
function v14.Resume(p17)
if u2() then
p17.CharacterSoundEvent:FireServer(true, false);
end;
if not p17.IsPlaying then
p17.Playing = true;
end;
end;
function v14.Stop(p18)
if u2() then
p18.CharacterSoundEvent:FireServer(false, true);
end;
if p18.IsPlaying then
p18.Playing = false;
end;
if p18.TimePosition ~= 0 then
p18.TimePosition = 0;
end;
end;
local u3 = {};
function setSoundInPlayingLoopedSounds(p19)
local v16 = #u3;
local v17 = 1 - 1;
while true do
if u3[v17] == p19 then
return;
end;
if 0 <= 1 then
if v17 < v16 then
else
break;
end;
elseif v16 < v17 then
else
break;
end;
v17 = v17 + 1;
end;
table.insert(u3, p19);
end;
function stopPlayingLoopedSoundsExcept(p20)
local v18 = #u3 - -1;
while true do
if u3[v18] ~= p20 then
v14.Pause(u3[v18]);
table.remove(u3, v18);
end;
if 0 <= -1 then
if v18 < 1 then
else
break;
end;
elseif 1 < v18 then
else
break;
end;
v18 = v18 + -1;
end;
end;
local v19 = {};
v19[Enum.HumanoidStateType.Dead] = function()
stopPlayingLoopedSoundsExcept();
v14.Play(v3[v1.Died]);
end;
v19[Enum.HumanoidStateType.RunningNoPhysics] = function(p21)
stateUpdated(Enum.HumanoidStateType.Running, p21);
end;
local u4 = UserSettings():IsUserFeatureEnabled("UserFixCharacterSoundIssues");
local u5 = nil;
local u6 = 0;
v19[Enum.HumanoidStateType.Running] = function(p22)
local v20 = v3[v1.Running];
stopPlayingLoopedSoundsExcept(v20);
if u4 and u5 == Enum.HumanoidStateType.Freefall and u6 > 0.1 then
local v21 = v3[v1.FreeFalling];
v21.Volume = math.min(1, math.max(0, (u6 - 50) / 110));
v14.Play(v21);
u6 = 0;
end;
if u4 then
if p22 ~= nil and p22 > 0.5 then
v14.Resume(v20);
setSoundInPlayingLoopedSounds(v20);
return;
elseif p22 ~= nil then
stopPlayingLoopedSoundsExcept();
return;
else
return;
end;
elseif not (v14.HorizontalSpeed(l__Head__10) > 0.5) then
stopPlayingLoopedSoundsExcept();
return;
end;
v14.Resume(v20);
setSoundInPlayingLoopedSounds(v20);
end;
v19[Enum.HumanoidStateType.Swimming] = function(p23)
if u4 then
local v22 = p23;
else
v22 = v14.VerticalSpeed(l__Head__10);
end;
if u5 ~= Enum.HumanoidStateType.Swimming and v22 > 0.1 then
local v23 = v3[v1.Splash];
v23.Volume = v14.Clamp(v14.YForLineGivenXAndTwoPts(v14.VerticalSpeed(l__Head__10), 100, 0.28, 350, 1), 0, 1);
v14.Play(v23);
end;
local v24 = v3[v1.Swimming];
stopPlayingLoopedSoundsExcept(v24);
v14.Resume(v24);
setSoundInPlayingLoopedSounds(v24);
end;
v19[Enum.HumanoidStateType.Climbing] = function(p24)
local v25 = v3[v1.Climbing];
if u4 then
if p24 ~= nil and math.abs(p24) > 0.1 then
v14.Resume(v25);
stopPlayingLoopedSoundsExcept(v25);
else
v14.Pause(v25);
stopPlayingLoopedSoundsExcept(v25);
end;
elseif v14.VerticalSpeed(l__Head__10) > 0.1 then
v14.Resume(v25);
stopPlayingLoopedSoundsExcept(v25);
else
stopPlayingLoopedSoundsExcept();
end;
setSoundInPlayingLoopedSounds(v25);
end;
v19[Enum.HumanoidStateType.Jumping] = function()
if u5 == Enum.HumanoidStateType.Jumping then
return;
end;
stopPlayingLoopedSoundsExcept();
v14.Play(v3[v1.Jumping]);
end;
v19[Enum.HumanoidStateType.GettingUp] = function()
stopPlayingLoopedSoundsExcept();
v14.Play(v3[v1.GettingUp]);
end;
v19[Enum.HumanoidStateType.Freefall] = function()
if u5 == Enum.HumanoidStateType.Freefall then
return;
end;
v3[v1.FreeFalling].Volume = 0;
stopPlayingLoopedSoundsExcept();
u6 = math.max(u6, math.abs(l__Head__10.Velocity.y));
end;
v19[Enum.HumanoidStateType.FallingDown] = function()
stopPlayingLoopedSoundsExcept();
end;
v19[Enum.HumanoidStateType.Landed] = function()
stopPlayingLoopedSoundsExcept();
if v14.VerticalSpeed(l__Head__10) > 75 then
local v26 = v3[v1.Landing];
v26.Volume = v14.Clamp(v14.YForLineGivenXAndTwoPts(v14.VerticalSpeed(l__Head__10), 50, 0, 100, 1), 0, 1);
v14.Play(v26);
end;
end;
v19[Enum.HumanoidStateType.Seated] = function()
stopPlayingLoopedSoundsExcept();
end;
function stateUpdated(p25, p26)
if v19[p25] ~= nil then
if u4 then
if p25 ~= Enum.HumanoidStateType.Running then
if p25 ~= Enum.HumanoidStateType.Climbing then
if p25 ~= Enum.HumanoidStateType.Swimming then
if p25 == Enum.HumanoidStateType.RunningNoPhysics then
v19[p25](p26);
else
v19[p25]();
end;
else
v19[p25](p26);
end;
else
v19[p25](p26);
end;
else
v19[p25](p26);
end;
else
v19[p25]();
end;
end;
u5 = p25;
end;
v2.Died:connect(function()
stateUpdated(Enum.HumanoidStateType.Dead);
end);
v2.Running:connect(function(p27)
stateUpdated(Enum.HumanoidStateType.Running, p27);
end);
v2.Swimming:connect(function(p28)
stateUpdated(Enum.HumanoidStateType.Swimming, p28);
end);
v2.Climbing:connect(function(p29)
stateUpdated(Enum.HumanoidStateType.Climbing, p29);
end);
v2.Jumping:connect(function()
stateUpdated(Enum.HumanoidStateType.Jumping);
end);
v2.GettingUp:connect(function()
stateUpdated(Enum.HumanoidStateType.GettingUp);
end);
v2.FreeFalling:connect(function()
stateUpdated(Enum.HumanoidStateType.Freefall);
end);
v2.FallingDown:connect(function()
stateUpdated(Enum.HumanoidStateType.FallingDown);
end);
v2.StateChanged:connect(function(p30, p31)
stateUpdated(p31);
end);
function onUpdate(p32, p33)
local v27 = v3[v1.FreeFalling];
if u5 == Enum.HumanoidStateType.Freefall then
if l__Head__10.Velocity.Y < 0 then
if 75 < v14.VerticalSpeed(l__Head__10) then
v14.Resume(v27);
v27.Volume = v14.Clamp(v27.Volume + p33 / 1.1 * (p32 / p33), 0, 1);
else
v27.Volume = 0;
end;
else
v27.Volume = 0;
end;
else
v14.Pause(v27);
end;
if u5 == Enum.HumanoidStateType.Running then
if v14.HorizontalSpeed(l__Head__10) < 0.5 then
v14.Pause(v3[v1.Running]);
end;
end;
end;
local v28 = tick();
while true do
onUpdate(tick() - v28, 0.25);
v28 = tick();
wait(0.25);
end; |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local l__Ice__1 = game.Players.LocalPlayer:WaitForChild("Data"):WaitForChild("Ice");
local l__Parent__1 = script.Parent;
l__Ice__1.Changed:Connect(function()
if l__Ice__1.Value <= 0.9 and l__Ice__1.Value >= 1 then
l__Parent__1.Crackle.Volume = 0.1;
return;
end;
if l__Ice__1.Value <= 0.1 and l__Ice__1.Value >= 0 then
l__Parent__1.Crackle.Volume = 0.9;
return;
end;
if l__Ice__1.Value <= 0.2 and l__Ice__1.Value >= 0.1 then
l__Parent__1.Crackle.Volume = 0.8;
return;
end;
if l__Ice__1.Value <= 0.3 and l__Ice__1.Value >= 0.2 then
l__Parent__1.Crackle.Volume = 0.7;
return;
end;
if l__Ice__1.Value <= 0.4 and l__Ice__1.Value >= 0.3 then
l__Parent__1.Crackle.Volume = 0.6;
return;
end;
if l__Ice__1.Value <= 0.5 and l__Ice__1.Value >= 0.4 then
l__Parent__1.Crackle.Volume = 0.5;
return;
end;
if l__Ice__1.Value <= 0.6 and l__Ice__1.Value >= 0.5 then
l__Parent__1.Crackle.Volume = 0.4;
return;
end;
if l__Ice__1.Value <= 0.7 and l__Ice__1.Value >= 0.6 then
l__Parent__1.Crackle.Volume = 0.3;
return;
end;
if l__Ice__1.Value <= 0.8 and l__Ice__1.Value >= 0.7 then
l__Parent__1.Crackle.Volume = 0.2;
return;
end;
if l__Ice__1.Value <= 0.9 then
l__Parent__1.Crackle.Volume = 0.1;
return;
end;
if l__Ice__1.Value >= 1 then
l__Parent__1.Crackle.Volume = 0;
end;
end); |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | script.Parent.Parent.Values.RPM.Changed:connect(function()
local t = 0
t = (totalPSI*20)
BOVact = math.floor(t)
end)
script.Parent.Parent.Values.RPM.Changed:connect(function()
wait(0.1)
local t2 = 0
t2 = (totalPSI*20)
BOVact2 = math.floor(t2)
end)
script.Parent.Parent.Values.RPM.Changed:connect(function()
if BOVact > BOVact2 then
if BOV.IsPlaying == false then
BOV:Play()
end
end
if BOVact < BOVact2 then
if BOV.IsPlaying == true then
BOV:Stop()
end
end
end) |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | --
local MouseLockController = {}
MouseLockController.__index = MouseLockController
function MouseLockController.new()
local self = setmetatable({}, MouseLockController)
self.isMouseLocked = false
self.savedMouseCursor = nil
self.boundKeys = {Enum.KeyCode.Z} -- defaults
self.mouseLockToggledEvent = Instance.new("BindableEvent")
local boundKeysObj: StringValue = script:FindFirstChild("BoundKeys") :: StringValue
if (not boundKeysObj) or (not boundKeysObj:IsA("StringValue")) then
-- If object with correct name was found, but it's not a StringValue, destroy and replace
if boundKeysObj then
boundKeysObj:Destroy()
end
boundKeysObj = Instance.new("StringValue")
boundKeysObj.Name = "BoundKeys"
boundKeysObj.Value = "Z"
boundKeysObj.Parent = script
end
if boundKeysObj then
boundKeysObj.Changed:Connect(function(value)
self:OnBoundKeysObjectChanged(value)
end)
self:OnBoundKeysObjectChanged(boundKeysObj.Value) -- Initial setup call
end
-- Watch for changes to user's ControlMode and ComputerMovementMode settings and update the feature availability accordingly
GameSettings.Changed:Connect(function(property)
if property == "ControlMode" or property == "ComputerMovementMode" then
self:UpdateMouseLockAvailability()
end
end)
-- Watch for changes to DevEnableMouseLock and update the feature availability accordingly
PlayersService.LocalPlayer:GetPropertyChangedSignal("DevEnableMouseLock"):Connect(function()
self:UpdateMouseLockAvailability()
end)
-- Watch for changes to DevEnableMouseLock and update the feature availability accordingly
PlayersService.LocalPlayer:GetPropertyChangedSignal("DevComputerMovementMode"):Connect(function()
self:UpdateMouseLockAvailability()
end)
self:UpdateMouseLockAvailability()
return self
end
function MouseLockController:GetIsMouseLocked()
return self.isMouseLocked
end
function MouseLockController:GetBindableToggleEvent()
return self.mouseLockToggledEvent.Event
end
function MouseLockController:GetMouseLockOffset()
local offsetValueObj: Vector3Value = script:FindFirstChild("CameraOffset") :: Vector3Value
if offsetValueObj and offsetValueObj:IsA("Vector3Value") then
return offsetValueObj.Value
else
-- If CameraOffset object was found but not correct type, destroy
if offsetValueObj then
offsetValueObj:Destroy()
end
offsetValueObj = Instance.new("Vector3Value")
offsetValueObj.Name = "CameraOffset"
offsetValueObj.Value = Vector3.new(1.75,0,0) -- Legacy Default Value
offsetValueObj.Parent = script
end
if offsetValueObj and offsetValueObj.Value then
return offsetValueObj.Value
end
return Vector3.new(1.75,0,0)
end
function MouseLockController:UpdateMouseLockAvailability()
local devAllowsMouseLock = PlayersService.LocalPlayer.DevEnableMouseLock
local devMovementModeIsScriptable = PlayersService.LocalPlayer.DevComputerMovementMode == Enum.DevComputerMovementMode.Scriptable
local userHasMouseLockModeEnabled = GameSettings.ControlMode == Enum.ControlMode.MouseLockSwitch
local userHasClickToMoveEnabled = GameSettings.ComputerMovementMode == Enum.ComputerMovementMode.ClickToMove
local MouseLockAvailable = devAllowsMouseLock and userHasMouseLockModeEnabled and not userHasClickToMoveEnabled and not devMovementModeIsScriptable
if MouseLockAvailable~=self.enabled then
self:EnableMouseLock(MouseLockAvailable)
end
end
function MouseLockController:OnBoundKeysObjectChanged(newValue: string)
self.boundKeys = {} -- Overriding defaults, note: possibly with nothing at all if boundKeysObj.Value is "" or contains invalid values
for token in string.gmatch(newValue,"[^%s,]+") do
for _, keyEnum in pairs(Enum.KeyCode:GetEnumItems()) do
if token == keyEnum.Name then
self.boundKeys[#self.boundKeys+1] = keyEnum :: Enum.KeyCode
break
end
end
end
self:UnbindContextActions()
self:BindContextActions()
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local SurfaceArtSelector = Roact.Component:extend("SurfaceArtSelector")
SurfaceArtSelector.defaultProps = {
numItemsPerPage = 3,
}
function SurfaceArtSelector:init()
self.isAnimating = false
self.position, self.updatePosition = Roact.createBinding(0)
self.target, self.updateTarget = Roact.createBinding(0)
self.motor = Otter.createSingleMotor(self.position:getValue())
self.motor:onStep(self.updatePosition)
self.state = {
-- Selected surface art index in self.props.images
selectedIndex = 1,
-- Offset to render overflow items in order to avoid empty items during pagination
offset = 0,
}
self.useSinglePagination = function()
return UserInputService.TouchEnabled or self.props.orientation.isPortrait
end
self.onApply = modules.onApply(self)
self.onCancel = modules.onCancel(self)
self.prevPage = function()
local prevPage = modules.prevPage(self)
prevPage(math.min(self.props.numItemsPerPage, #self.props.images))
end
self.prevItem = function()
local prevPage = modules.prevPage(self)
prevPage(1)
end
self.nextPage = function()
local nextPage = modules.nextPage(self)
nextPage(math.min(self.props.numItemsPerPage, #self.props.images))
end
self.nextItem = function()
local nextPage = modules.nextPage(self)
nextPage(1)
end
self.setCurrentIndex = modules.setCurrentIndex(self)
self.getRenderedIndexes = modules.getRenderedIndexes(self)
self.formatTargetIndex = modules.formatTargetIndex()
self.getItemTransparency = modules.getItemTransparency(self)
end
function SurfaceArtSelector:render()
local items = {
UIListLayout = Roact.createElement("UIListLayout", {
SortOrder = Enum.SortOrder.LayoutOrder,
FillDirection = Enum.FillDirection.Horizontal,
VerticalAlignment = Enum.VerticalAlignment.Center,
HorizontalAlignment = Enum.HorizontalAlignment.Center,
}),
}
local indexes = self.getRenderedIndexes()
local mid = math.floor((#indexes + 1) / 2)
for i, index in ipairs(indexes) do
-- Avoid the same image being shown as selected when they are shown on the same page
local isSelected = self.state.selectedIndex == index and i == mid
-- Offset from the current selected index
local offset = mid - i
local item = Roact.createElement("Frame", {
LayoutOrder = i,
BackgroundTransparency = 1,
AutomaticSize = Enum.AutomaticSize.XY,
}, {
Roact.createElement(SurfaceArtSelectorItem, {
image = self.props.images[index],
isSelected = isSelected,
transparency = self.getItemTransparency(i, index, mid),
onClick = function()
self.setCurrentIndex(index, offset)
end,
}),
})
items[self.formatTargetIndex(index, offset)] = item
end
local actionBarHeight = self.props.orientation.isPortrait and ACTION_BAR_HEIGHT_PORTRAIT
or ACTION_BAR_HEIGHT_LANDSCAPE
return Roact.createElement("Frame", {
Size = UDim2.fromScale(1, 1),
BackgroundTransparency = 1,
}, {
Background = Roact.createElement("Frame", {
Size = UDim2.fromScale(1, 1),
BackgroundColor3 = Color3.fromRGB(0, 0, 0),
ZIndex = 1,
}, {
Gradient = Roact.createElement("UIGradient", {
Transparency = NumberSequence.new({
NumberSequenceKeypoint.new(0, 0),
NumberSequenceKeypoint.new(0.2, 0.5),
NumberSequenceKeypoint.new(0.8, 0.5),
NumberSequenceKeypoint.new(1, 0),
}),
Rotation = self.props.orientation.isPortrait and 90 or 0,
}),
}),
Container = Roact.createElement("Frame", {
Size = UDim2.fromScale(1, 1),
BackgroundTransparency = 1,
ZIndex = 2,
}, {
Scroller = Roact.createElement("Frame", {
Size = UDim2.new(1, 0, 1, -(actionBarHeight + ACTION_BAR_TOP_SPACING)),
BackgroundTransparency = 1,
Position = UDim2.fromScale(0.5, 0.5),
AnchorPoint = Vector2.new(0.5, 0.5),
ZIndex = 1,
}, {
UIListLayout = Roact.createElement("UIListLayout", {
FillDirection = Enum.FillDirection.Horizontal,
SortOrder = Enum.SortOrder.LayoutOrder,
}),
LeftButton = not self.useSinglePagination() and Roact.createElement(NavButton, {
order = 1,
image = self.props.configuration.leftArrowPageImage,
onClick = self.prevPage,
keyCode = self.props.configuration.usePageHotkeys and self.props.configuration.prevPageKey or nil,
}),
LeftSingleButton = Roact.createElement(NavButton, {
order = 2,
image = self.props.configuration.leftArrowItemImage,
keyCode = self.props.configuration.usePageHotkeys and self.props.configuration.prevItemKey or nil,
onClick = self.prevItem,
}),
Page = Roact.createElement("Frame", {
LayoutOrder = 3,
Size = self.useSinglePagination() and UDim2.fromScale(0.8, 1) or UDim2.fromScale(0.6, 1),
BackgroundTransparency = 1,
ClipsDescendants = true,
}, {
Container = Roact.createElement("Frame", {
BackgroundTransparency = 1,
Size = UDim2.fromScale(1, 1),
AnchorPoint = Vector2.new(0.5, 0.5),
Position = self.position:map(function(position)
-- Calculate position for animation using pixel offset instead of scale.
--
-- This is because this Frame's size is not computed with all SurfaceArtSelectorItems rendered, but only
-- those that are visible.
return UDim2.new(0.5, position, 0.5, 0)
end),
}, items),
}),
RightSingleButton = Roact.createElement(NavButton, {
order = 4,
image = self.props.configuration.rightArrowItemImage,
onClick = self.nextItem,
keyCode = self.props.configuration.usePageHotkeys and self.props.configuration.nextItemKey or nil,
}),
RightButton = not self.useSinglePagination() and Roact.createElement(NavButton, {
order = 5,
image = self.props.configuration.rightArrowPageImage,
onClick = self.nextPage,
keyCode = self.props.configuration.usePageHotkeys and self.props.configuration.nextPageKey or nil,
}),
}),
ActionBar = Roact.createElement("Frame", {
Size = UDim2.new(1, 0, 0, actionBarHeight + ACTION_BAR_TOP_SPACING),
BackgroundTransparency = 0.5,
BackgroundColor3 = Color3.fromRGB(0, 0, 0),
Position = UDim2.fromScale(0.5, 1),
AnchorPoint = Vector2.new(0.5, 1),
ZIndex = 3,
}, {
UIPadding = Roact.createElement("UIPadding", {
PaddingTop = UDim.new(0, 16),
PaddingBottom = UDim.new(0, 16),
}),
UIListLayout = Roact.createElement("UIListLayout", {
SortOrder = Enum.SortOrder.LayoutOrder,
}),
TextLabel = Roact.createElement("TextLabel", {
LayoutOrder = 1,
Size = UDim2.fromScale(1, self.props.orientation.isPortrait and 0.5 or 0.4),
BackgroundTransparency = 1,
TextSize = 16,
Font = Enum.Font.GothamSemibold,
TextColor3 = Color3.fromRGB(255, 255, 255),
TextYAlignment = Enum.TextYAlignment.Top,
TextXAlignment = Enum.TextXAlignment.Center,
TextWrapped = true,
Text = string.format(
"Choose a decal to place on the wall. You can add up to %d decals.",
self.props.configuration.quotaPerPlayer
),
}, {
UIPadding = Roact.createElement("UIPadding", {
PaddingLeft = UDim.new(0, 8),
PaddingRight = UDim.new(0, 8),
}),
}),
Roact.createElement("Frame", {
LayoutOrder = 2,
Size = UDim2.fromScale(1, self.props.orientation.isPortrait and 0.5 or 0.6),
BackgroundTransparency = 1,
}, {
ButtonGroup = Roact.createElement("Frame", {
Size = UDim2.fromScale(0.5, 1),
BackgroundTransparency = 1,
Position = UDim2.fromScale(0.5, 0.5),
AnchorPoint = Vector2.new(0.5, 0.5),
}, {
UIListLayout = Roact.createElement("UIListLayout", {
FillDirection = Enum.FillDirection.Horizontal,
SortOrder = Enum.SortOrder.LayoutOrder,
Padding = UDim.new(0, 12),
}),
Cancel = Roact.createElement(Button, {
LayoutOrder = 1,
Text = "Cancel",
TextColor3 = Color3.fromRGB(255, 255, 255),
keyCode = Enum.KeyCode.B,
onActivated = self.onCancel,
}),
Apply = Roact.createElement(Button, {
LayoutOrder = 2,
Text = "Apply",
BackgroundColor3 = Color3.fromRGB(255, 255, 255),
TextColor3 = Color3.fromRGB(0, 0, 0),
keyCode = Enum.KeyCode.Return,
onActivated = self.onApply,
}),
}),
}),
}),
}),
})
end
return ConfigurationContext.withConfiguration(OrientationContext.withOrientation(SurfaceArtSelector)) |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | function IconController.setGameTheme(theme)
IconController.gameTheme = theme
local icons = IconController.getIcons()
for _, icon in pairs(icons) do
icon:setTheme(theme)
end
end
function IconController.setDisplayOrder(value)
value = tonumber(value) or TopbarPlusGui.DisplayOrder
TopbarPlusGui.DisplayOrder = value
end
IconController.setDisplayOrder(10)
function IconController.getIcons()
local allIcons = {}
for otherIcon, _ in pairs(topbarIcons) do
table.insert(allIcons, otherIcon)
end
return allIcons
end
function IconController.getIcon(name)
for otherIcon, _ in pairs(topbarIcons) do
if otherIcon.name == name then
return otherIcon
end
end
return false
end
function IconController.disableHealthbar(bool)
local finalBool = (bool == nil or bool)
IconController.healthbarDisabled = finalBool
IconController.healthbarDisabledSignal:Fire(finalBool)
end
function IconController.canShowIconOnTopbar(icon)
if (icon.enabled == true or icon.accountForWhenDisabled) and icon.presentOnTopbar then
return true
end
return false
end
function IconController.getMenuOffset(icon)
local alignment = icon:get("alignment")
local alignmentGap = IconController[alignment.."Gap"]
local iconSize = icon:get("iconSize") or UDim2.new(0, 32, 0, 32)
local sizeX = iconSize.X.Offset
local iconWidthAndGap = (sizeX + alignmentGap)
local extendLeft = 0
local extendRight = 0
local additionalRight = 0
if icon.menuOpen then
local menuSize = icon:get("menuSize")
local menuSizeXOffset = menuSize.X.Offset
local direction = icon:_getMenuDirection()
if direction == "right" then
extendRight += menuSizeXOffset + alignmentGap/6--2
elseif direction == "left" then
extendLeft = menuSizeXOffset + 4
extendRight += alignmentGap/3--4
additionalRight = menuSizeXOffset
end
end
return extendLeft, extendRight, additionalRight
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local O = true
function onClicked()
if O == true then
O = false
One()
elseif O == false then
O = true
Two()
end
end
script.Parent.MouseButton1Down:connect(onClicked) |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | return function(tbl)
--- Variables
local found = false
--- Scan local function
local function Scan(v)
--- Already found userdata
if found then
return
end
--- Iterate
for key, value in pairs(v) do
--- Already found userdata
if found then
return
end
--- Main check
if type(value) == "userdata" or type(key) == "userdata" then
--- Userdata located
found = true
return
elseif type(value) == "table" then
--- Re-iterate
Scan(value)
end
end
end
--- Scan
Scan(tbl)
--
return found
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | function TaskScheduler:CreateScheduler(targetFps)
local scheduler = {}
local queue = {}
local sleeping = true
local event,paused
local start
local frameUpdateTable = {}
local sleep--get syntax highlighter to shut up on line 68
local function onEvent()
local iterationStart = tick()
local targetFrameUpdates = (iterationStart-start) < 1 and math.floor(targetFps * (iterationStart-start)) or targetFps
for i=#frameUpdateTable,1,-1 do
frameUpdateTable[i+1] = (frameUpdateTable[i] >= iterationStart-1) and frameUpdateTable[i] or nil
end
frameUpdateTable[1] = iterationStart
if #frameUpdateTable >= targetFrameUpdates then
if #queue > 0 then
queue[1]()
table.remove(queue, 1)
else
sleep()
end
end
end
--used for automatically turning off renderstepped loop when there's nothing in the queue
sleep = function()
sleeping = true
if event then
event:disconnect()
event = nil
end
end
--turns renderstepped loop back on when something is added to the queue and scheduler isn't paused
local function wake()
if sleeping and not event then
sleeping = false
if not paused then
start = tick()
event = game:GetService("RunService").RenderStepped:connect(onEvent)
end
end
end
function scheduler:Pause()
paused = true
if event then
event:disconnect()
event = nil
end
end
function scheduler:Resume()
if paused and not event then
paused = false
sleeping = false
start = tick()
event = game:GetService("RunService").RenderStepped:connect(onEvent)
end
end
function scheduler:Destroy()
scheduler:Pause()
for i in next,scheduler do
scheduler[i] = nil
end
setmetatable(scheduler, {
__index = function()
error("Attempt to use destroyed scheduler")
end;
__newindex = function()
error("Attempt to use destroyed scheduler")
end;
})
end
function scheduler:QueueTask(callback)
queue[#queue+1] = callback
if sleeping then
wake()
end
end
start = tick()
event = game:GetService("RunService").RenderStepped:connect(onEvent)
return scheduler
end
return TaskScheduler |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | for name, fileList in pairs(animNames) do
animTable[name] = {}
animTable[name].count = 0
animTable[name].totalWeight = 0
-- check for config values
local config = script:FindFirstChild(name)
if (config ~= nil) then |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local u1 = nil;
coroutine.wrap(function()
u1 = require(game.ReplicatedStorage:WaitForChild("Resources"));
end)();
local v1 = {
New = function(p1, p2, p3, p4)
p2 = p2 or Color3.new(0.2, 0.2, 0.2);
p3 = p3 or Enum.Font.FredokaOne;
p4 = p4 or Enum.FontSize.Size18;
u1.StarterGui:SetCore("ChatMakeSystemMessage", {
Text = p1,
Color = p2,
Font = p3,
FontSize = p4
});
end
};
u1.Network.Fired("Chat Msg"):Connect(function(...)
v1.New(...);
end);
return v1; |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local function fields(defaults)
if defaults == nil then
defaults = {}
end
return function(input)
local _object = {}
for _k, _v in pairs(defaults) do
_object[_k] = _v
end
if type(input) == "table" then
for _k, _v in pairs(input) do
_object[_k] = _v
end
end
return _object
end
end
return {
fields = fields,
} |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local set = script.Settings
local sp = set.Speed
local enabled = set.Enabled
local loop = set.Loop
local debug_ = set.Debug
local hum = script.Parent:WaitForChild("Humanoid")
if debug_.Value == true then
if hum then
print("Success")
else
print("No Humanoid")
end
end
local humanim = hum:LoadAnimation(script:FindFirstChildOfClass("Animation")) |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local DoorFX = {}
local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
function DoorFX.OPEN(door)
if not door then return end
for i = 1, 2 do
tweenService:Create(door["Door" .. i].PrimaryPart, tweenInfo, {CFrame = door["Door"..i.."Goal"].CFrame}):Play()
door["Door" .. i].PrimaryPart.DoorOpenFADEOUT:Play()
end
end
function DoorFX.CLOSE(door)
if not door then return end
for i = 1, 2 do
door["Door" .. i].PrimaryPart.CFrame = door["Door"..i.."Start"].CFrame
end
end
return DoorFX |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | function ServiceBag:Init()
assert(not self._initializing, "Already initializing")
assert(self._serviceTypesToInitializeSet, "Already initialized")
self._initializing = true
while next(self._serviceTypesToInitializeSet) do
local serviceType = next(self._serviceTypesToInitializeSet)
self._serviceTypesToInitializeSet[serviceType] = nil
self:_ensureInitialization(serviceType)
end
self._serviceTypesToInitializeSet = nil
self._initializing = false
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local Pcolors = {{255, 255, 255}, {255, 180, 161}, {226, 231, 255}}
local Lcolors = {{255, 255, 255}, {255, 237, 199}, {205, 227, 255}}
local INDcolor = {255, 130, 80}
local plactive = false
local prevChild
F.Setup = function(light_type, popups, tb, fog_color)
event.IndicatorsAfterLeave.Disabled = true
for idx, child in pairs(lights.Brake:GetChildren()) do
if child.Name == "L" and #child:GetChildren() < 1 then
local spot = Instance.new("SpotLight", child)
spot.Name = "L"
spot.Brightness = 0
spot.Range = 0
spot.Face = Enum.NormalId.Back
spot.Color = Color3.fromRGB(255, 0, 0)
spot.Shadows = true
elseif child.Name == "LN" then
if child:IsA("MeshPart") then
child.TextureID = ""
end
child.Material = Enum.Material.Neon
child.Color = Color3.fromRGB(255, 96, 96)
child.Transparency = 1
end
end
for idx, child in pairs(lights.Rear:GetChildren()) do
if child.Name == "L" and #child:GetChildren() < 1 then
local spot = Instance.new("SpotLight", child)
spot.Name = "L"
spot.Brightness = 0
spot.Range = 0
spot.Face = Enum.NormalId.Back
spot.Color = Color3.fromRGB(255, 0, 0)
spot.Shadows = true
elseif child.Name == "LN" then
if child:IsA("MeshPart") then
child.TextureID = ""
end
child.Material = Enum.Material.Neon
child.Color = Color3.fromRGB(255, 96, 96)
child.Transparency = 1
end
end
for idx, child in pairs(lights.Reverse:GetChildren()) do
if child.Name == "L" and #child:GetChildren() < 1 then
local spot = Instance.new("SpotLight", child)
spot.Name = "L"
spot.Brightness = 0
spot.Range = 0
spot.Face = Enum.NormalId.Back
spot.Color = Color3.fromRGB(255, 255, 255)
spot.Shadows = true
elseif child.Name == "LN" then
if child:IsA("MeshPart") then
child.TextureID = ""
end
child.Material = Enum.Material.Neon
child.Color = Color3.fromRGB(255, 255, 255)
child.Transparency = 1
end
end
for idx, child in pairs(lights.LeftInd:GetDescendants()) do
if child.Name == "L" and child.Parent.Name == "Front" and #child:GetChildren() < 1 then
local spot = Instance.new("SpotLight", child)
spot.Name = "L"
spot.Brightness = 0
spot.Range = 0
spot.Face = Enum.NormalId.Front
spot.Color = Color3.fromRGB(INDcolor[1], INDcolor[2], INDcolor[3])
spot.Shadows = true
elseif child.Name == "L" and child.Parent.Name == "Rear" and #child:GetChildren() < 1 then
local spot = Instance.new("SpotLight", child)
spot.Name = "L"
spot.Brightness = 0
spot.Range = 0
spot.Face = Enum.NormalId.Back
spot.Color = Color3.fromRGB(INDcolor[1], INDcolor[2], INDcolor[3])
spot.Shadows = true
elseif child.Name == "L" and child.Parent.Name == "Side" and #child:GetChildren() < 1 then
local spot = Instance.new("SpotLight", child)
spot.Name = "L"
spot.Brightness = 0
spot.Range = 0
spot.Face = Enum.NormalId.Left
spot.Color = Color3.fromRGB(INDcolor[1], INDcolor[2], INDcolor[3])
spot.Shadows = true
elseif child.Name == "LN" then
if child:IsA("MeshPart") then
child.TextureID = ""
end
child.Material = Enum.Material.Neon
child.Color = Color3.fromRGB(INDcolor[1], INDcolor[2], INDcolor[3])
child.Transparency = 1
elseif string.sub(child.Name, 1, 2) == "SI" then
if child:IsA("MeshPart") then
child.TextureID = ""
end
child.Material = Enum.Material.Neon
child.Color = Color3.fromRGB(INDcolor[1], INDcolor[2], INDcolor[3])
child.Transparency = 1
end
end
for idx, child in pairs(lights.RightInd:GetDescendants()) do
if child.Name == "L" and child.Parent.Name == "Front" and #child:GetChildren() < 1 then
local spot = Instance.new("SpotLight", child)
spot.Name = "L"
spot.Brightness = 0
spot.Range = 0
spot.Face = Enum.NormalId.Front
spot.Color = Color3.fromRGB(INDcolor[1], INDcolor[2], INDcolor[3])
spot.Shadows = true
elseif child.Name == "L" and child.Parent.Name == "Rear" and #child:GetChildren() < 1 then
local spot = Instance.new("SpotLight", child)
spot.Name = "L"
spot.Brightness = 0
spot.Range = 0
spot.Face = Enum.NormalId.Back
spot.Color = Color3.fromRGB(INDcolor[1], INDcolor[2], INDcolor[3])
spot.Shadows = true
elseif child.Name == "L" and child.Parent.Name == "Side" and #child:GetChildren() < 1 then
local spot = Instance.new("SpotLight", child)
spot.Name = "L"
spot.Brightness = 0
spot.Range = 0
spot.Face = Enum.NormalId.Right
spot.Color = Color3.fromRGB(INDcolor[1], INDcolor[2], INDcolor[3])
spot.Shadows = true
elseif child.Name == "LN" then
if child:IsA("MeshPart") then
child.TextureID = ""
end
child.Material = Enum.Material.Neon
child.Color = Color3.fromRGB(INDcolor[1], INDcolor[2], INDcolor[3])
child.Transparency = 1
elseif string.sub(child.Name, 1, 2) == "SI" then
if child:IsA("MeshPart") then
child.TextureID = ""
end
child.Material = Enum.Material.Neon
child.Color = Color3.fromRGB(INDcolor[1], INDcolor[2], INDcolor[3])
child.Transparency = 1
end
end
for idx, child in pairs(tb) do
child.ImageTransparency = 1
end
if not popups then
if light_type == "Pure White" then
for idx, child in pairs(lights.Headlights:GetDescendants()) do
if child.Name == "L" and #child:GetChildren() < 1 then
local spot = Instance.new("SpotLight", child)
spot.Name = "L"
spot.Brightness = 0
spot.Range = 0
spot.Face = Enum.NormalId.Front
spot.Color = Color3.fromRGB(Lcolors[1][1], Lcolors[1][2], Lcolors[1][3])
spot.Shadows = true
elseif child.Name == "LN" then
if child:IsA("MeshPart") then
child.TextureID = ""
end
child.Material = Enum.Material.Neon
child.Color = Color3.fromRGB(Pcolors[1][1], Pcolors[1][2], Pcolors[1][3])
child.Transparency = 1
end
end
elseif light_type == "OEM White" then
for idx, child in pairs(lights.Headlights:GetDescendants()) do
if child.Name == "L" and #child:GetChildren() < 1 then
local spot = Instance.new("SpotLight", child)
spot.Name = "L"
spot.Brightness = 0
spot.Range = 0
spot.Face = Enum.NormalId.Front
spot.Color = Color3.fromRGB(Lcolors[2][1], Lcolors[2][2], Lcolors[2][3])
spot.Shadows = true
elseif child.Name == "LN" then
if child:IsA("MeshPart") then
child.TextureID = ""
end
child.Material = Enum.Material.Neon
child.Color = Color3.fromRGB(Pcolors[2][1], Pcolors[2][2], Pcolors[2][3])
child.Transparency = 1
end
end
elseif light_type == "Xenon" then
for idx, child in pairs(lights.Headlights:GetDescendants()) do
if child.Name == "L" and #child:GetChildren() < 1 then
local spot = Instance.new("SpotLight", child)
spot.Name = "L"
spot.Brightness = 0
spot.Range = 0
spot.Face = Enum.NormalId.Front
spot.Color = Color3.fromRGB(Lcolors[3][1], Lcolors[3][2], Lcolors[3][3])
spot.Shadows = true
elseif child.Name == "LN" then
if child:IsA("MeshPart") then
child.TextureID = ""
end
child.Material = Enum.Material.Neon
child.Color = Color3.fromRGB(Pcolors[3][1], Pcolors[3][2], Pcolors[3][3])
child.Transparency = 1
end
end
end
else
if light_type == "Pure White" then
for idx, child in pairs(PHeadlights.Parts.Headlights:GetChildren()) do
if child.Name == "L" and #child:GetChildren() < 1 then
local spot = Instance.new("SpotLight", child)
spot.Name = "L"
spot.Brightness = 0
spot.Range = 0
spot.Face = Enum.NormalId.Front
spot.Color = Color3.fromRGB(Lcolors[1][1], Lcolors[1][2], Lcolors[1][3])
spot.Shadows = true
elseif child.Name == "LN" then
if child:IsA("MeshPart") then
child.TextureID = ""
end
child.Material = Enum.Material.Neon
child.Color = Color3.fromRGB(Pcolors[1][1], Pcolors[1][2], Pcolors[1][3])
child.Transparency = 1
end
end
elseif light_type == "OEM White" then
for idx, child in pairs(PHeadlights.Parts.Headlights:GetChildren()) do
if child.Name == "L" and #child:GetChildren() < 1 then
local spot = Instance.new("SpotLight", child)
spot.Name = "L"
spot.Brightness = 0
spot.Range = 0
spot.Face = Enum.NormalId.Front
spot.Color = Color3.fromRGB(Lcolors[2][1], Lcolors[2][2], Lcolors[2][3])
spot.Shadows = true
elseif child.Name == "LN" then
if child:IsA("MeshPart") then
child.TextureID = ""
end
child.Material = Enum.Material.Neon
child.Color = Color3.fromRGB(Pcolors[2][1], Pcolors[2][2], Pcolors[2][3])
child.Transparency = 1
end
end
elseif light_type == "Xenon" then
for idx, child in pairs(PHeadlights.Parts.Headlights:GetChildren()) do
if child.Name == "L" and #child:GetChildren() < 1 then
local spot = Instance.new("SpotLight", child)
spot.Name = "L"
spot.Brightness = 0
spot.Range = 0
spot.Face = Enum.NormalId.Front
spot.Color = Color3.fromRGB(Lcolors[3][1], Lcolors[3][2], Lcolors[3][3])
spot.Shadows = true
elseif child.Name == "LN" then
if child:IsA("MeshPart") then
child.TextureID = ""
end
child.Material = Enum.Material.Neon
child.Color = Color3.fromRGB(Pcolors[3][1], Pcolors[3][2], Pcolors[3][3])
child.Transparency = 1
end
end
end
end
for idx, child in pairs(lights.Fog:GetChildren()) do
if child.Name == "L" then
local spot = Instance.new("SpotLight", child)
spot.Name = "L"
spot.Brightness = 0
spot.Range = 0
spot.Face = Enum.NormalId.Front
spot.Color = fog_color
spot.Shadows = true
elseif child.Name == "LN" then
if child:IsA("MeshPart") then
child.TextureID = ""
end
child.Material = Enum.Material.Neon
child.Color = fog_color
child.Transparency = 1
end
end
print("EpicLights Version 2 // Setup completed!")
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | function NpcModule.Walk(Npc, Pos, PathParams, Return)
local Path = NpcModule.GetPath(Npc, Pos, PathParams)
local Humanoid = Npc:FindFirstChild("Humanoid")
if Path ~= false then
if Humanoid then
for I, Waypoint in pairs(Path:GetWaypoints()) do
Humanoid:MoveTo(Waypoint.Position)
Humanoid.MoveToFinished:Wait()
end
end
end
if Return ~= nil then
return
end
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | function onRunning(speed)
if speed>0 then
pose = "Running"
else
pose = "Standing"
end
end
function onDied()
pose = "Dead"
end
function onJumping()
pose = "Jumping"
end
function onClimbing()
pose = "Climbing"
end
function onGettingUp()
pose = "GettingUp"
end
function onFreeFall()
pose = "FreeFall"
end
function onFallingDown()
pose = "FallingDown"
end
function onSeated()
pose = "Seated"
end
function onPlatformStanding()
pose = "PlatformStanding"
end
function onSwimming(speed)
if speed>0 then
pose = "Running"
else
pose = "Standing"
end
end
function moveJump()
RightShoulder.MaxVelocity = jumpMaxLimbVelocity
LeftShoulder.MaxVelocity = jumpMaxLimbVelocity
RightShoulder:SetDesiredAngle(3.14)
LeftShoulder:SetDesiredAngle(-3.14)
RightHip:SetDesiredAngle(0)
LeftHip:SetDesiredAngle(0)
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local function AddRecentApp(App)
if RecentAppEnabled == true then
local sameapp = false
if home:FindFirstChild(App) then
if side.RecentApps:FindFirstChild(App) then
sameapp = true
end
side.Status:TweenPosition(UDim2.new(0.094,0,0.638,0), "InOut", "Quint", 0.5, true)
side.B1:TweenPosition(UDim2.new(0.024,0,0.593,0), "InOut", "Quint", 0.5, true)
for i, v in pairs(side.RecentApps:GetChildren()) do
if v.Position == UDim2.new(0.016,0,0.345,0) then
if sameapp and side.RecentApps:FindFirstChild(App) then
if side.RecentApps[App].Position ~= UDim2.new(0.015,0,0.027,0) then
v:TweenPosition(UDim2.new(0.032,0,0.668,0), "InOut", "Quint", 0.25, true)
end
else
v:TweenPosition(UDim2.new(0.032,0,0.668,0), "InOut", "Quint", 0.25, true)
end
end
if v.Position == UDim2.new(0.015,0,0.027,0) then
v:TweenPosition(UDim2.new(0.016,0,0.345,0), "InOut", "Quint", 0.25, true)
end
if v.Name == App then --prevents any same apps to be duplicated ok
v:TweenPosition(UDim2.new(0.015,0,0.027,0), "InOut", "Quint", 0.25, true)
end
if v.Position == UDim2.new(0.032,0,0.668,0) then
if not sameapp then
for i = 0, 1, 0.2 do
wait()
v.ImageTransparency = i
end
v:Destroy()
end
end
end
if not sameapp then
local app = home:FindFirstChild(App):Clone()
app.Parent = side.RecentApps
app.IconName.Visible = false
app.ZIndex = 102
app.Size = UDim2.new(0.968, 0, 0.358, 0)
app.ImageTransparency = 1
app.Position = UDim2.new(0.015,0,0.027,0)
for i = 1, 0, -0.2 do
wait()
app.ImageTransparency = i
end
end
end
end
end
local function PlayMusic(Title, ID, pitch)
local musictitle = script.Parent.CarPlay.NowPlaying.MusicTitle
local id = script.Parent.CarPlay.NowPlaying.MusicID
musictitle.Text = Title
id.Text = ID
filter:FireServer("updateSong", ID, pitch)
handler:FireServer("PlayMusic", Title, ID)
nowplaying.Play.ImageRectOffset = Vector2.new(150, 0)
end
local function PlayMusicUsingSongValue(Val, Playlists, pitch)
if script.Parent.CarPlay_Data.Playlists:FindFirstChild(Playlists) then
local musictitle = script.Parent.CarPlay.NowPlaying.MusicTitle
local id = script.Parent.CarPlay.NowPlaying.MusicID
local playlists = script.Parent.CarPlay_Data.Playlists[Playlists]:GetChildren()
musictitle.Text = playlists[Val].Name
handler:FireServer("PlayMusic", playlists[Val].Name, playlists[Val].Value)
id.Text = playlists[Val].Value
filter:FireServer("updateSong", playlists[Val].Value, playlists[Val].Pitch.Value)
end
end
local function LaunchApp(AppToLaunch)
if home:FindFirstChild(AppToLaunch) then
handler:FireServer("LaunchApp", AppToLaunch)
for i, app in ipairs(home:GetChildren()) do
app.AppEnabled.Value = false -- no jerks that can mess carplay
end
AddRecentApp(AppToLaunch)
home[AppToLaunch].IconName.Visible = false
home[AppToLaunch].ZIndex = 102
X = home[AppToLaunch].Position.X.Scale
Y = home[AppToLaunch].Position.Y.Scale
home[AppToLaunch]:TweenSizeAndPosition(UDim2.new(1.599, 0,2.591, 0), UDim2.new(-0.325, 0,-0.965, 0), "Out", "Quint", 1.2, true)
home[AppToLaunch].Parent = script.Parent.CarPlay.Homescreen
for i, app in ipairs(script.Parent.CarPlay:GetChildren()) do
if app.Name == AppToLaunch then
app.Visible = true
end
end
home.Visible = false
for i = 0, 1, 0.2 do
wait()
home.Parent[AppToLaunch].ImageTransparency = i
end
home.Parent.Visible = false
end
end
local function LaunchHome()
for i, v in pairs(home.Parent:GetChildren()) do
if v.Name == "Music" or v.Name == "Maps" or v.Name == "Settings" or v.Name == "BMW" or v.Name == "NowPlaying" or v.Name == "Podcasts" or v.Name == "Phone" then
handler:FireServer("LaunchHome")
script.Parent.CarPlay.Music.Library.Visible = true
script.Parent.CarPlay.Music.Playlists.Visible = false
for i, app in pairs(script.Parent.CarPlay:GetChildren()) do
if app:IsA("Frame") and app.Visible == true then
app.Visible = false
end
end
script.Parent.CarPlay:FindFirstChild(v.Name).Visible = false
home.Parent.Visible = true
v:TweenSizeAndPosition(UDim2.new(0.23,0,1,0), UDim2.new(X,0,Y,0), "Out", "Quint", 0.5, true)
home.Visible = true
v.ImageTransparency = 0
v.ZIndex = 2
v.IconName.Visible = true
v.Parent = home
wait(.4)
for i, app in pairs(home:GetChildren()) do
if app:FindFirstChild("AppEnabled") then
app.AppEnabled.Value = true -- no jerks that can mess carplay
end
end
end
end
end
local function LoadPlaylist(PlaylistName)
local Y = 0
local NextY = 0.039
music.Playlists.MusicPlaylist:ClearAllChildren()
local Data = script.Parent.CarPlay_Data.Playlists[PlaylistName]
music.Playlists.PlaylistName.Text = PlaylistName
for i, musics in ipairs(Data:GetChildren()) do
if musics:IsA("IntValue") then
handler:FireServer("LoadPlaylist",PlaylistName, musics.Name, musics.Value, Y)
local Template = music.Playlists.Template:Clone()
Template.Name = musics.Value
Template.MusicTitle.Text = musics.Name
Template.MusicID.Text = musics.Value
Template.Position = UDim2.new(0.037,0,Y,0)
Template.Parent = music.Playlists.MusicPlaylist
Template.Pitch.Value = musics.Pitch.Value
Template.Visible = true
Y = Y + NextY
end
end
for i, playlists in ipairs(script.Parent.CarPlay.Music.Playlists.MusicPlaylist:GetChildren()) do
if playlists:IsA("TextButton") then
playlists.MouseButton1Down:connect(function()
TransitionTo("Playlists", "NowPlaying")
AddRecentApp("NowPlaying")
script.Parent.CarPlay_Data.NowPlayingData.CurrentPlaylist.Value = PlaylistName
script.Parent.CarPlay_Data.NowPlayingData.SongNumber.Value = i
PlayMusic(playlists.MusicTitle.Text, playlists.MusicID.Text, playlists.Pitch.Value)
end)
end
end
end
local function CreatePlaylists()
local Y = 0.002
local NextY = 0.092
music.Library.LibraryButtons:ClearAllChildren()
local Data = script.Parent.CarPlay_Data.Playlists
for i, playlists in ipairs(Data:GetChildren()) do
if playlists:IsA("Folder") then
local Template = music.Library:WaitForChild('Template'):Clone()
Template.Parent = music.Library.LibraryButtons
Template.Name = playlists.Name
Template.Visible = true
handler:FireServer("CreatePlaylist", playlists.Name, Y)
Template.PlaylistName.Text = playlists.Name
Template.Position = UDim2.new(0.025, 0, Y, 0)
Y = Y + NextY
end
end
for i, playlists in ipairs(script.Parent.CarPlay.Music.Library.LibraryButtons:GetChildren()) do
if playlists:IsA("TextButton") then
playlists.MouseButton1Down:connect(function()
TransitionTo("Library", "Playlists")
LoadPlaylist(playlists.Name)
end)
end
end
end
function TransitionTo(Prev, Next)
if debounce == false then
debounce = true
for i, frame in ipairs(script.Parent.CarPlay:GetDescendants()) do
if frame:IsA("Frame") and frame.Name == Prev then
frame:TweenPosition(UDim2.new(-1,0,0,0), "Out", "Quint", 0.5, true)
local framediss = coroutine.wrap(function()
wait(.5)
frame.Position = UDim2.new(0,0,0,0)
frame.Visible = false
end)
framediss()
end
if frame:IsA("Frame") and frame.Name == Next then
frame.Visible = true
frame.Position = UDim2.new(1,0,0,0)
frame:TweenPosition(UDim2.new(0,0,0,0), "Out", "Quint", 0.5, true)
end
handler:FireServer("Transition", Prev, Next)
debounce = false
end
end
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | ScrollingFrame = NewGui('ScrollingFrame', 'ScrollingFrame')
ScrollingFrame.Selectable = false
ScrollingFrame.CanvasSize = UDim2.new(0, 0, 0, 0)
ScrollingFrame.Parent = InventoryFrame
UIGridFrame = NewGui('Frame', 'UIGridFrame')
UIGridFrame.Selectable = false
UIGridFrame.Size = UDim2.new(1, -(ICON_BUFFER*2), 1, 0)
UIGridFrame.Position = UDim2.new(0, ICON_BUFFER, 0, 0)
UIGridFrame.Parent = ScrollingFrame
UIGridLayout = Instance.new("UIGridLayout")
UIGridLayout.SortOrder = Enum.SortOrder.LayoutOrder
UIGridLayout.CellSize = UDim2.new(0, ICON_SIZE, 0, ICON_SIZE)
UIGridLayout.CellPadding = UDim2.new(0, ICON_BUFFER, 0, ICON_BUFFER)
UIGridLayout.Parent = UIGridFrame
ScrollUpInventoryButton = MakeVRRoundButton('ScrollUpButton', 'rbxasset://textures/ui/Backpack/ScrollUpArrow.png')
ScrollUpInventoryButton.Size = UDim2.new(0, 34, 0, 34)
ScrollUpInventoryButton.Position = UDim2.new(0.5, -ScrollUpInventoryButton.Size.X.Offset/2, 0, INVENTORY_HEADER_SIZE + 3)
ScrollUpInventoryButton.Icon.Position = ScrollUpInventoryButton.Icon.Position - UDim2.new(0,0,0,2)
ScrollUpInventoryButton.MouseButton1Click:Connect(function()
ScrollingFrame.CanvasPosition = Vector2.new(
ScrollingFrame.CanvasPosition.X,
Clamp(0, ScrollingFrame.CanvasSize.Y.Offset - ScrollingFrame.AbsoluteWindowSize.Y, ScrollingFrame.CanvasPosition.Y - (ICON_BUFFER + ICON_SIZE)))
end)
ScrollDownInventoryButton = MakeVRRoundButton('ScrollDownButton', 'rbxasset://textures/ui/Backpack/ScrollUpArrow.png')
ScrollDownInventoryButton.Rotation = 180
ScrollDownInventoryButton.Icon.Position = ScrollDownInventoryButton.Icon.Position - UDim2.new(0,0,0,2)
ScrollDownInventoryButton.Size = UDim2.new(0, 34, 0, 34)
ScrollDownInventoryButton.Position = UDim2.new(0.5, -ScrollDownInventoryButton.Size.X.Offset/2, 1, -ScrollDownInventoryButton.Size.Y.Offset - 3)
ScrollDownInventoryButton.MouseButton1Click:Connect(function()
ScrollingFrame.CanvasPosition = Vector2.new(
ScrollingFrame.CanvasPosition.X,
Clamp(0, ScrollingFrame.CanvasSize.Y.Offset - ScrollingFrame.AbsoluteWindowSize.Y, ScrollingFrame.CanvasPosition.Y + (ICON_BUFFER + ICON_SIZE)))
end)
ScrollingFrame.Changed:Connect(function(prop)
if prop == 'AbsoluteWindowSize' or prop == 'CanvasPosition' or prop == 'CanvasSize' then
local canScrollUp = ScrollingFrame.CanvasPosition.Y ~= 0
local canScrollDown = ScrollingFrame.CanvasPosition.Y < ScrollingFrame.CanvasSize.Y.Offset - ScrollingFrame.AbsoluteWindowSize.Y
ScrollUpInventoryButton.Visible = canScrollUp
ScrollDownInventoryButton.Visible = canScrollDown
end
end) |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | if not shellyGood then bp.Parent,bg.Parent= nil,nil return end
bp.Parent = nil
wait(math.random(3,8))
end
local soundBank = game.ServerStorage.Sounds.NPC.Shelly:GetChildren()
shelly.Health.Changed:connect(function()
if shellyGood then
bp.Parent,bg.Parent= nil,nil
shelly.PrimaryPart.Transparency =1
shelly.PrimaryPart.CanCollide = false
shelly.Shell.Transparency = 1
shelly.HitShell.Transparency = 0
shelly.HitShell.CanCollide = true
shellyGood = false
ostrich = tick()
shelly:SetPrimaryPartCFrame(shelly.PrimaryPart.CFrame*CFrame.new(0,2,0))
local hitSound = soundBank[math.random(1,#soundBank)]:Clone()
hitSound.PlayOnRemove = true
hitSound.Parent = shelly.PrimaryPart
wait()
hitSound:Destroy()
repeat task.wait() until tick()-ostrich > 10
shelly.PrimaryPart.Transparency = 0
shelly.PrimaryPart.CanCollide = true
shelly.Shell.Transparency = 0
shelly.HitShell.Transparency = 1
shelly.HitShell.CanCollide = false
bp.Parent,bg.Parent = shelly.PrimaryPart,shelly.PrimaryPart
shellyGood = true
end
end)
while true do
if shellyGood then
MoveShelly()
else
task.wait(1)
end
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local KEY_BASE_FRAME = "BaseFrame"
local KEY_BASE_MESSAGE = "BaseMessage"
local KEY_UPDATE_TEXT_FUNC = "UpdateTextFunction"
local KEY_GET_HEIGHT = "GetHeightFunction"
local KEY_FADE_IN = "FadeInFunction"
local KEY_FADE_OUT = "FadeOutFunction"
local KEY_UPDATE_ANIMATION = "UpdateAnimFunction"
local TextService = game:GetService("TextService")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
while not LocalPlayer do
Players.ChildAdded:wait()
LocalPlayer = Players.LocalPlayer
end
local clientChatModules = script.Parent.Parent
local ChatSettings = require(clientChatModules:WaitForChild("ChatSettings"))
local ChatConstants = require(clientChatModules:WaitForChild("ChatConstants"))
local module = {}
local methods = {}
methods.__index = methods
function methods:GetStringTextBounds(text, font, textSize, sizeBounds)
sizeBounds = sizeBounds or Vector2.new(10000, 10000)
return TextService:GetTextSize(text, textSize, font, sizeBounds)
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | function RemoteSignal:Connect(fn)
if self._directConnect then
return self._re.OnServerEvent:Connect(fn)
else
return self._signal:Connect(fn)
end
end
function RemoteSignal:_processOutboundMiddleware(player: Player?, ...: any)
if not self._hasOutbound then
return ...
end
local args = table.pack(...)
for _,middlewareFunc in ipairs(self._outbound) do
local middlewareResult = table.pack(middlewareFunc(player, args))
if not middlewareResult[1] then
return table.unpack(middlewareResult, 2, middlewareResult.n)
end
end
return table.unpack(args, 1, args.n)
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | ["Walk"] = "http://www.roblox.com/asset/?id=507767714",
["Idle"] = "http://www.roblox.com/asset/?id=507766666",
["SwingTool"] = "rbxassetid://1262318281"
}
local anims = {}
for animName,animId in next,preAnims do
local anim = Instance.new("Animation")
anim.AnimationId = animId
game:GetService("ContentProvider"):PreloadAsync({anim})
anims[animName] = animController:LoadAnimation(anim)
end
local fallConstant = -2
run.Heartbeat:connect(function()
local part,pos,norm,mat = workspace:FindPartOnRay(Ray.new(root.Position,Vector3.new(0,-2.8,0)),char)
if target.Value then
local facingCFrame = CFrame.new(Vector3.new(root.CFrame.X,pos.Y+3,root.CFrame.Z),CFrame.new(target.Value.CFrame.X,pos.Y+3,target.Value.CFrame.Z).p)
bg.CFrame = facingCFrame
else
--bg.CFrame = CFrame.new(root.CFrame.X,pos.Y+3,root.CFrame.Z)
end
if target.Value then
bv.P = 100000
bv.Velocity = root.CFrame.lookVector*10
if not part then
bv.Velocity = bv.Velocity+Vector3.new(0,fallConstant,0)
fallConstant = fallConstant-1
else
fallConstant = -2
end
if not anims["Walk"].IsPlaying then
anims["Walk"]:Play()
end
else
bv.P = 0
bv.Velocity = Vector3.new(0,0,0)
anims["Walk"]:Stop()
anims["Idle"]:Play()
end
end)
while true do
local thresh,nearest = 60,nil
for _,player in next,game.Players:GetPlayers() do
if player.Character and player.Character.PrimaryPart then
local dist = (player.Character.PrimaryPart.Position-root.Position).magnitude
if dist < thresh then
thresh = dist
nearest = player.Character.PrimaryPart
end
end
end
if nearest then
if thresh < 5 then
anims["SwingTool"]:Play()
nearest.Parent.Humanoid:TakeDamage(8)
target.Value = nil
wait(1)
end
target.Value = nearest
else
target.Value = nil
end
wait(1)
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | return function(data, env)
if env then
setfenv(1, env)
end
local playergui = service.PlayerGui
local localplayer = service.Players.LocalPlayer
local scr = client.UI.Prepare(script.Parent.Parent)
local window = scr.Window
local msg = data.Message
local color = data.Color
local found = client.UI.Get("Output")
if found then
for i,v in pairs(found) do
local p = v.Object
if p and p.Parent then
p.Window.Position = UDim2.new(0.5, 0, 0.5, p.Window.Position.Y.Offset+160)
end
end
end
window.Main.ScrollingFrame.ErrorText.Text = msg
window.Main.ScrollingFrame.ErrorText.TextColor3 = color
window.Close.MouseButton1Down:Connect(function()
gTable.Destroy()
end)
spawn(function()
local sound = Instance.new("Sound",service.LocalContainer())
sound.SoundId = "rbxassetid://160715357"
sound.Volume = 2
sound:Play()
wait(0.8)
sound:Destroy()
end)
gTable.Ready()
wait(5)
gTable.Destroy()
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | bike.DriveSeat.ChildRemoved:connect(function(child)
--[[if child.Name=="SeatWeld" and child:IsA("Weld") then
script.Parent:Destroy()
end]]
bike.Body.bal.LeanGyro.D = 0
bike.Body.bal.LeanGyro.MaxTorque = Vector3.new(0,0,0)
bike.Body.bal.LeanGyro.P = 0
bike.RearSection.Axle.HingeConstraint.MotorMaxTorque = 0
end) |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | ha=false
hd=false
hs=false
hw=false
imgassets ={
hazardoff="http://www.roblox.com/asset/?id=216957891",
hazardon = "http://www.roblox.com/asset/?id=216957887",
leftyoff = "http://www.roblox.com/asset/?id=216957962",
leftyon = "http://www.roblox.com/asset/?id=216957949",
rightyoff = "http://www.roblox.com/asset/?id=216957912",
rightyon = "http://www.roblox.com/asset/?id=216957903",
outoff="http://www.roblox.com/asset/?id=216957880",
outon = "http://www.roblox.com/asset/?id=216957874",
sirensoff = "http://www.roblox.com/asset/?id=216958870",
sirenson = "http://www.roblox.com/asset/?id=216958870",
wailoff = "http://www.roblox.com/asset/?id=216930335",
wailon = "http://www.roblox.com/asset/?id=216930318",
x4off = "http://www.roblox.com/asset/?id=216954211",
x4on = "http://www.roblox.com/asset/?id=216954202",
x2off = "http://www.roblox.com/asset/?id=216958009",
x2on = "http://www.roblox.com/asset/?id=216958007",
fastoff = "http://www.roblox.com/asset/?id=216957982",
faston = "http://www.roblox.com/asset/?id=216957977",
slowoff = "http://www.roblox.com/asset/?id=216957998",
slowon = "http://www.roblox.com/asset/?id=216957989",
lightsoff = "http://www.roblox.com/asset/?id=115931775",
lightson = "http://www.roblox.com/asset/?id=115931779",
lockoff = "http://www.roblox.com/asset/?id=116532096",
lockon = "http://www.roblox.com/asset/?id=116532114",
leftturn = "http://www.roblox.com/asset/?id=115931542",
rightturn = "http://www.roblox.com/asset/?id=115931529",
fltd = "http://www.roblox.com/asset/?id=116531501",
yelpon = "http://www.roblox.com/asset/?id=216930350",
yelpoff = "http://www.roblox.com/asset/?id=216930359",
phaseron = "http://www.roblox.com/asset/?id=216930382",
phaseroff = "http://www.roblox.com/asset/?id=216930390",
hiloon = "http://www.roblox.com/asset/?id=216930459",
hilooff = "http://www.roblox.com/asset/?id=216930471",
hornon = "http://www.roblox.com/asset/?id=216930428",
hornoff = "http://www.roblox.com/asset/?id=216930438",
wailrumbleron = "http://www.roblox.com/asset/?id=216930512",
wailrumbleroff = "http://www.roblox.com/asset/?id=216930520",
yelprumbleron = "http://www.roblox.com/asset/?id=216930566",
yelprumbleroff = "http://www.roblox.com/asset/?id=216930573",
phaserrumbleron = "http://www.roblox.com/asset/?id=216930585",
phaserrumbleroff = "http://www.roblox.com/asset/?id=216930595",
hyperhiloon = "http://www.roblox.com/asset/?id=216963140",
hyperhilooff = "http://www.roblox.com/asset/?id=216963128",
}
for _,i in pairs (imgassets) do
Game:GetService("ContentProvider"):Preload(i)
end
if gear == 1 then
script.Parent.dn.TextColor3 = Color3.new(.3,.3,.3)
script.Parent.dn.Style = "RobloxRoundButton"
end
if gear == maxgear then
script.Parent.up.TextColor3 = Color3.new(.3,.3,.3)
script.Parent.up.Style = "RobloxRoundButton"
end
function gearup()--activated by GUI or pressing E
if lock then return end
if gear < maxgear then
gear = gear+1
watdo()
script.Parent.Gear.Text = (gear.."/"..maxgear)
end
if gear == maxgear then
script.Parent.up.TextColor3 = Color3.new(.3,.3,.3)
script.Parent.up.Style = "RobloxRoundButton"
script.Parent.dn.TextColor3 = Color3.new(1,1,1)
script.Parent.dn.Style = "RobloxRoundButton"
elseif gear == 1 then
script.Parent.dn.TextColor3 = Color3.new(.3,.3,.3)
script.Parent.dn.Style = "RobloxRoundButton"
script.Parent.up.TextColor3 = Color3.new(1,1,1)
script.Parent.up.Style = "RobloxRoundButton"
else
script.Parent.dn.TextColor3 = Color3.new(1,1,1)
script.Parent.dn.Style = "RobloxRoundButton"
script.Parent.up.TextColor3 = Color3.new(1,1,1)
script.Parent.up.Style = "RobloxRoundButton"
end
end
function geardown()--activated by GUI or pressing Q
if lock then return end
if gear > 1 then
gear = gear-1
watdo()
script.Parent.Gear.Text = (gear.."/"..maxgear)
end
if gear == 1 then
script.Parent.dn.TextColor3 = Color3.new(.3,.3,.3)
script.Parent.dn.Style = "RobloxRoundButton"
script.Parent.up.TextColor3 = Color3.new(1,1,1)
script.Parent.up.Style = "RobloxRoundButton"
elseif gear == maxgear then
script.Parent.up.TextColor3 = Color3.new(.3,.3,.3)
script.Parent.up.Style = "RobloxRoundButton"
script.Parent.dn.TextColor3 = Color3.new(1,1,1)
script.Parent.dn.Style = "RobloxRoundButton"
else
script.Parent.dn.TextColor3 = Color3.new(1,1,1)
script.Parent.dn.Style = "RobloxRoundButton"
script.Parent.up.TextColor3 = Color3.new(1,1,1)
script.Parent.up.Style = "RobloxRoundButton"
end
end
script.Parent.up.MouseButton1Click:connect(gearup)
script.Parent.dn.MouseButton1Click:connect(geardown)
script.Parent.up.MouseButton1Click:connect(gearup)
script.Parent.dn.MouseButton1Click:connect(geardown)
script.Parent.flipbutton.MouseButton1Click:connect(function()
if not flipping then
flipping = true
local a = Instance.new("BodyPosition",seat)
a.maxForce = Vector3.new(100000,10000000,100000)
a.position = seat.Position + Vector3.new(0,10,0)
local b = Instance.new("BodyGyro",seat)
wait(3)
a:Destroy()
b:Destroy()
flipping = false
end
end)
function turn()
if turndebounce == false then
turndebounce = true
wait(0.05)
repeat
templeft = turningleft
tempright = turningright
script.Parent.onsound:Play()
if turningleft == true then
script.Parent.leftturn.Visible = true
for _,i in pairs (leftturn) do
i.BrickColor = BrickColor.new("Deep orange")
end
for _,a in pairs (leftlight) do
a.BrickColor = BrickColor.new("Really red")
end
for _,b in pairs (leftflash) do
if lightson then
b.Enabled = true
end
end
for _,b in pairs (leftbrake) do
b.Brightness = 2
end
end
if turningright == true then
script.Parent.rightturn.Visible = true
for _,i in pairs (rightturn) do
i.BrickColor = BrickColor.new("Deep orange")
end
for _,a in pairs (rightlight) do
a.BrickColor = BrickColor.new("Really red")
end
for _,b in pairs (rightflash) do
if lightson then
b.Enabled = true
end
end
for _,b in pairs (rightbrake) do
b.Brightness = 2
end
end
wait(0.4)
script.Parent.offsound:Play()
script.Parent.leftturn.Visible = false
script.Parent.rightturn.Visible = false
if templeft == true then
for _,i in pairs (leftturn) do
i.BrickColor = BrickColor.new("Neon orange")
end
for _,b in pairs (leftflash) do
b.Enabled = false
end
for _,a in pairs (leftlight) do
a.BrickColor = BrickColor.new("Bright red")
end
for _,b in pairs (leftbrake) do
b.Brightness = 1
end
else
if throttle > 0 then
for _,a in pairs (leftlight) do
a.BrickColor = BrickColor.new("Bright red")
end
for _,b in pairs (leftbrake) do
b.Brightness = 1
end
else
for _,a in pairs (leftlight) do
a.BrickColor = BrickColor.new("Really red")
end
for _,b in pairs (leftbrake) do
b.Brightness = 2
end
end
end
if tempright == true then
for _,i in pairs (rightturn) do
i.BrickColor = BrickColor.new("Neon orange")
end
for _,b in pairs (rightflash) do
b.Enabled = false
end
for _,a in pairs (rightlight) do
a.BrickColor = BrickColor.new("Bright red")
end
for _,b in pairs (rightbrake) do
b.Brightness = 1
end
else
if throttle > 0 then
for _,a in pairs (rightlight) do
a.BrickColor = BrickColor.new("Bright red")
end
for _,b in pairs (rightbrake) do
b.Brightness = 1
end
else
for _,a in pairs (rightlight) do
a.BrickColor = BrickColor.new("Really red")
end
for _,b in pairs (rightbrake) do
b.Brightness = 2
end
end
end
wait(0.35)
until turningleft == false and turningright == false
turndebounce = false
end
end
seat.ChildRemoved:connect(function(it)
if it:IsA("Weld") then
if it.Part1.Parent == Player.Character then
lock = true
ha=false
hd=false
hs=false
hw=false
throttle = 0
steer = 0
watdo()
script.Parent.close.Active = true
script.Parent.close.Visible = true
script.Parent.xlabel.Visible = true
end
end
end)
seat.ChildAdded:connect(function(it)
if it:IsA("Weld") then
if it.Part1.Parent == Player.Character then
lock = false
script.Parent.close.Active = false
script.Parent.close.Visible = false
script.Parent.xlabel.Visible = false
end
end
end)
function exiting()
lock = true--when we close the gui stop everything
steer = 0
throttle = 0
watdo()
turningleft = false
turningright = false
script.Parent.flasher.Value = false
script.Parent.siren.Value = false
lightson = false
Instance.new("IntValue",seat)
for _,i in pairs (leftturn) do
i.BrickColor = BrickColor.new("Neon orange")
end
for _,a in pairs (leftlight) do
a.BrickColor = BrickColor.new("Really red")
end
for _,b in pairs (leftflash) do
b.Enabled = false
end
for _,b in pairs (leftbrake) do
b.Brightness = 2
end
for _,i in pairs (rightturn) do
i.BrickColor = BrickColor.new("Neon orange")
end
for _,a in pairs (rightlight) do
a.BrickColor = BrickColor.new("Really red")
end
for _,b in pairs (rightflash) do
b.Enabled = false
end
for _,b in pairs (rightbrake) do
b.Brightness = 2
end
script.Parent.Parent:Destroy()--destroy the 'Car' ScreenGui
end
function updatelights()
for _,i in pairs (leftbrake) do
i.Enabled = lightson
end
for _,i in pairs (rightbrake) do
i.Enabled = lightson
end
for _,i in pairs (brakelight) do
i.Enabled = lightson
end
for _,i in pairs (headlight) do
i.Enabled = lightson
end
if lightson then
script.Parent.lightimage.Image = imgassets.lightson
else
script.Parent.lightimage.Image = imgassets.lightsoff
end
end
script.Parent.lights.MouseButton1Click:connect(function()
if lock then return end
lightson = not lightson
updatelights()
end)
function destroycar()
seat.Parent:Destroy()--destroy the car
end
script.Parent.close.MouseButton1Up:connect(exiting)
Player.Character.Humanoid.Died:connect(destroycar)
game.Players.PlayerRemoving:connect(function(Playeras)
if Playeras.Name == Player.Name then
destroycar()
end
end)
for _, i in pairs (seat.Parent:GetChildren()) do--populate the tables for ease of modularity. You could have 100 left wheels if you wanted.
if i.Name == "LeftWheel" then
table.insert(left,i)
elseif i.Name == "RightWheel" then
table.insert(right,i)
elseif i.Name == "Rearlight" then
table.insert(rearlight,i)
elseif i.Name == "Brakelight" then
table.insert(brakelight,i.SpotLight)
elseif i.Name == "rightturn" then
table.insert(rightturn,i)
elseif i.Name == "leftturn" then
table.insert(leftturn,i)
elseif i.Name == "leftflash" then
table.insert(leftflash,i.SpotLight)
elseif i.Name == "rightflash" then
table.insert(rightflash,i.SpotLight)
elseif i.Name == "leftlight" then
table.insert(leftlight,i)
elseif i.Name == "rightlight" then
table.insert(rightlight,i)
elseif i.Name == "Headlight" then
table.insert(headlight,i.SpotLight)
elseif i.Name == "leftbrake" then
table.insert(leftbrake,i.SpotLight)
elseif i.Name == "rightbrake" then
table.insert(rightbrake,i.SpotLight)
elseif i.Name == "revlight" then
table.insert(revlight,i.SpotLight)
end
end
for _,l in pairs (left) do
l.BottomParamA = 0
l.BottomParamB = 0
end
for _,r in pairs (right) do
r.BottomParamA = 0
r.BottomParamB = 0
end
function watdo()
seat.Parent.LeftMotor.DesiredAngle = math.rad(throttle < 0 and 40* steer or 40*steer/gear^0.5)
seat.Parent.RightMotor.DesiredAngle = math.rad(throttle < 0 and 40* steer or 40*steer/gear^0.5)
for _,l in pairs (left) do--I do it this way so that it's not searching the model every time an input happens
if throttle ~= -1 then
l.BottomParamA = (.1/gear)
l.BottomParamB = (.5*gear+steer*gear/30)*throttle
else
l.BottomParamA = -.01
l.BottomParamB = -.5-steer/20
end
end
for _,r in pairs (right) do
if throttle ~= -1 then
r.BottomParamA = -(.1/gear)
r.BottomParamB = -(.5*gear-steer*gear/30)*throttle
else
r.BottomParamA = .01
r.BottomParamB = .5-steer/20
end
end
if throttle < 1 then
for _,g in pairs (rearlight) do
g.BrickColor = BrickColor.new("Really red")
end
for _,b in pairs (brakelight) do
b.Brightness = 2
end
if turningleft == false then
for _,a in pairs (leftlight) do
a.BrickColor = BrickColor.new("Really red")
end
for _,b in pairs (leftbrake) do
b.Brightness = 2
end
end
if turningright == false then
for _,a in pairs (rightlight) do
a.BrickColor = BrickColor.new("Really red")
end
for _,b in pairs (rightbrake) do
b.Brightness = 2
end
end
else
for _,g in pairs (rearlight) do
g.BrickColor = BrickColor.new("Bright red")
end
for _,b in pairs (brakelight) do
b.Brightness = 1
end
if turningleft == false then
for _,a in pairs (leftlight) do
a.BrickColor = BrickColor.new("Bright red")
end
for _,b in pairs (leftbrake) do
b.Brightness = 1
end
end
if turningright == false then
for _,a in pairs (rightlight) do
a.BrickColor = BrickColor.new("Bright red")
end
for _,b in pairs (rightbrake) do
b.Brightness = 1
end
end
end
if throttle < 0 then
for _,b in pairs (revlight) do
if lightson then
b.Enabled = true
end
end
else
for _,b in pairs (revlight) do
b.Enabled = false
end
end
end
Player:GetMouse().KeyDown:connect(function(key)--warning ugly button code
if lock then return end
key = string.upper(key)
if not ha and key == "A" or key == string.char(20) and not ha then
ha = true
steer = steer-1
end
if not hd and key == "D" or key == string.char(19) and not hd then
hd = true
steer = steer+1
end
if not hw and key == "W" or key == string.char(17) and not hw then
hw = true
throttle = throttle+1
end
if not hs and key == "S" or key == string.char(18) and not hs then
hs = true
throttle = throttle-1
end
if key == "Z" then
geardown()
end
if key == "X" then
gearup()
end
if key == "Q" then
turningleft = not turningleft
turn()
end
if key == "E" then
turningright = not turningright
turn()
end
watdo()
end)
Player:GetMouse().KeyUp:connect(function(key)
if lock then return end
key = string.upper(key)
if ha and key == "A" or key == string.char(20)and ha then
steer = steer+1
ha = false
end
if hd and key == "D" or key == string.char(19) and hd then
steer = steer-1
hd = false
end
if hw and key == "W" or key == string.char(17) and hw then
throttle = throttle-1
hw = false
end
if hs and key == "S" or key == string.char(18) and hs then
throttle = throttle+1
hs = false
end
if key == "" then
--more keys if I need them
end
watdo()
end) |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local function Flip()
--Detect Orientation
if (car.DriveSeat.CFrame*CFrame.Angles(math.pi/2,0,0)).lookVector.y > .1 or FlipDB then
FlipWait=tick()
--Apply Flip
else
if tick()-FlipWait>=3 then
FlipDB=true
local gyro = car.DriveSeat.Flip
gyro.maxTorque = Vector3.new(10000,0,10000)
gyro.P=3000
gyro.D=500
wait(1)
gyro.maxTorque = Vector3.new(0,0,0)
gyro.P=0
gyro.D=0
FlipDB=false
end
end
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local function onProductPurchased(player, id)
local product, class = getAsset(id)
if product then
local data = Datastore:GetData(player)
if product.onPurchased then
product.onPurchased(player)
end
if class == "Passes" and data then
local gamepasses = data.Gamepasses or {}
table.insert(gamepasses, product.Id)
data.Gamepasses = gamepasses
end
end
end
MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, id, success)
if (success and player.Parent) then
onProductPurchased(player, id)
game.ReplicatedStorage.RE.gamepassUpdate:FireClient(player, getNameFromID(id))
end
end)
MarketplaceService.PromptProductPurchaseFinished:Connect(function(userid, id, success)
local player = game.Players:GetPlayerByUserId(userid)
if (success and player and player.Parent) then
onProductPurchased(player, id)
end
end) |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | amplitude = 0.1
frequency = 1
setAngles = true
end
if (setAngles) then
local desiredAngle = amplitude * math.sin(time * frequency)
RightShoulder:SetDesiredAngle(desiredAngle + climbFudge)
LeftShoulder:SetDesiredAngle(desiredAngle - climbFudge)
RightHip:SetDesiredAngle(-desiredAngle)
LeftHip:SetDesiredAngle(-desiredAngle)
end
-- Tool Animation handling
local tool = getTool()
if tool then
local animStringValueObject = getToolAnim(tool)
if animStringValueObject then
toolAnim = animStringValueObject.Value
-- message recieved, delete StringValue
animStringValueObject.Parent = nil
toolAnimTime = time + .3
end
if time > toolAnimTime then
toolAnimTime = 0
toolAnim = "None"
end
animateTool()
else
stopToolAnimations()
toolAnim = "None"
toolAnimTime = 0
end
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local function toggleDoor(player, door)
-- Check distance to the character's Torso. If too far, don't do anything
if player.Character and player.Character:FindFirstChild("Torso") then
local torso = player.Character:FindFirstChild("Torso")
local toTorso = torso.Position - stove.Door.Position
if toTorso.magnitude < clickDistance then
if open then
ovenMotor.DesiredAngle = 0
open = false
else
ovenMotor.DesiredAngle = math.pi/2
open = true
end
end
end
end
stove.DoorPadding.ROBLOXInteractionEvent.OnServerEvent:connect(function(player, arguments)
toggleDoor(player)
end)
stove.Door.ROBLOXInteractionEvent.OnServerEvent:connect(function(player, arguments)
toggleDoor(player)
end) |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | _diff_cleanupSemanticLossless = function(diffs: Array<Diff>)
local pointer = 2
-- Intentionally ignore the first and last element (don't need checking).
while diffs[pointer + 1] do
local prevDiff, nextDiff = diffs[pointer - 1], diffs[pointer + 1]
if prevDiff[1] == DIFF_EQUAL and nextDiff[1] == DIFF_EQUAL then
-- This is a single edit surrounded by equalities.
local diff = diffs[pointer]
local equality1 = prevDiff[2]
local edit = diff[2]
local equality2 = nextDiff[2]
-- First, shift the edit as far left as possible.
local commonOffset = _diff_commonSuffix(equality1, edit)
if commonOffset > 0 then
local commonString = strsub(edit, -commonOffset)
equality1 = strsub(equality1, 1, -commonOffset - 1)
edit = commonString .. strsub(edit, 1, -commonOffset - 1)
equality2 = commonString .. equality2
end
-- Second, step character by character right, looking for the best fit.
local bestEquality1 = equality1
local bestEdit = edit
local bestEquality2 = equality2
local bestScore = _diff_cleanupSemanticScore(equality1, edit) + _diff_cleanupSemanticScore(edit, equality2)
while strbyte(edit, 1) == strbyte(equality2, 1) do
equality1 = equality1 .. strsub(edit, 1, 1)
edit = strsub(edit, 2) .. strsub(equality2, 1, 1)
equality2 = strsub(equality2, 2)
local score = _diff_cleanupSemanticScore(equality1, edit) + _diff_cleanupSemanticScore(edit, equality2)
-- The >= encourages trailing rather than leading whitespace on edits.
if score >= bestScore then
bestScore = score
bestEquality1 = equality1
bestEdit = edit
bestEquality2 = equality2
end
end
if prevDiff[2] ~= bestEquality1 then
-- We have an improvement, save it back to the diff.
if #bestEquality1 > 0 then
diffs[pointer - 1][2] = bestEquality1
else
tremove(diffs, pointer - 1)
pointer = pointer - 1
end
diffs[pointer][2] = bestEdit
if #bestEquality2 > 0 then
diffs[pointer + 1][2] = bestEquality2
else
tremove(diffs, pointer + 1)
pointer -= 1
end
end
end
pointer += 1
end
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | function ActionManager:BindGameActions(players)
for i, player in pairs(players) do
bind:FireClient(player, "Action1", Enum.UserInputType.MouseButton1, Enum.KeyCode.ButtonR2)
end
end
function ActionManager:UnbindGameActions(players)
for i, player in pairs(players) do
unbind:FireClient(player, "Action1")
end
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local function makeProperty(valueObjectClass, defaultValue, setter)
local valueObject = Instance.new(valueObjectClass)
if defaultValue then
valueObject.Value = defaultValue
end
valueObject.Changed:connect(setter)
setter(valueObject.Value)
return valueObject
end
local Color = makeProperty("Color3Value", RAIN_DEFAULT_COLOR, function(value)
local value = ColorSequence.new(value)
Emitter.RainStraight.Color = value
Emitter.RainTopDown.Color = value
for _,v in pairs(splashAttachments) do
v.RainSplash.Color = value
end
for _,v in pairs(rainAttachments) do
v.RainStraight.Color = value
v.RainTopDown.Color = value
end
end)
local function updateTransparency(value)
local opacity = (1 - value) * (1 - GlobalModifier.Value)
local transparency = 1 - opacity
straightLowAlpha = RAIN_STRAIGHT_ALPHA_LOW * opacity + transparency
topdownLowAlpha = RAIN_TOPDOWN_ALPHA_LOW * opacity + transparency
local splashSequence = NumberSequence.new {
NSK010;
NumberSequenceKeypoint.new(RAIN_TRANSPARENCY_T1, opacity*RAIN_SPLASH_ALPHA_LOW + transparency, 0);
NumberSequenceKeypoint.new(RAIN_TRANSPARENCY_T2, opacity*RAIN_SPLASH_ALPHA_LOW + transparency, 0);
NSK110;
}
for _,v in pairs(splashAttachments) do
v.RainSplash.Transparency = splashSequence
end
end
local Transparency = makeProperty("NumberValue", RAIN_DEFAULT_TRANSPARENCY, updateTransparency)
GlobalModifier.Changed:connect(updateTransparency)
local SpeedRatio = makeProperty("NumberValue", RAIN_DEFAULT_SPEEDRATIO, function(value)
Emitter.RainStraight.Speed = NumberRange.new(value * RAIN_STRAIGHT_MAX_SPEED)
Emitter.RainTopDown.Speed = NumberRange.new(value * RAIN_TOPDOWN_MAX_SPEED)
end)
local IntensityRatio = makeProperty("NumberValue", RAIN_DEFAULT_INTENSITYRATIO, function(value)
Emitter.RainStraight.Rate = RAIN_STRAIGHT_MAX_RATE * value
Emitter.RainTopDown.Rate = RAIN_TOPDOWN_MAX_RATE * value
intensityOccludedRain = math.ceil(RAIN_OCCLUDED_MAXINTENSITY * value)
numSplashes = RAIN_SPLASH_NUM * value
end)
local LightEmission = makeProperty("NumberValue", RAIN_DEFAULT_LIGHTEMISSION, function(value)
Emitter.RainStraight.LightEmission = value
Emitter.RainTopDown.LightEmission = value
for _,v in pairs(rainAttachments) do
v.RainStraight.LightEmission = value
v.RainTopDown.LightEmission = value
end
for _,v in pairs(splashAttachments) do
v.RainSplash.LightEmission = value
end
end)
local LightInfluence = makeProperty("NumberValue", RAIN_DEFAULT_LIGHTINFLUENCE, function(value)
Emitter.RainStraight.LightInfluence = value
Emitter.RainTopDown.LightInfluence = value
for _,v in pairs(rainAttachments) do
v.RainStraight.LightInfluence = value
v.RainTopDown.LightInfluence = value
end
for _,v in pairs(splashAttachments) do
v.RainSplash.LightInfluence = value
end
end)
local RainDirection = makeProperty("Vector3Value", RAIN_DEFAULT_DIRECTION, function(value)
if value.magnitude > 0.001 then
rainDirection = value.unit
end
end) |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | --
local function validateAndSendSoundRequest(requestingPly, parent, soundObj, vol, pit, timePos)
if not soundObj then return end
for _, v in pairs(serverWorkerModule.getAllOtherPlayers(requestingPly)) do
playSoundEffectEvent:FireClient(v, parent, soundObj, vol, pit, timePos)
end
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local triggerEnabled = true
local function touched(otherPart)
if( not triggerEnabled ) then
return
end
if(otherPart.Name == "HumanoidRootPart" ) then
local player = game.Players:FindFirstChild(otherPart.Parent.Name)
if(player) then
triggerEnabled = false
staticCorrupt.Transparency = 0
imageLableCorrupt.ImageTransparency = 0
-- PlaySound("")
wait( 4 ) --How long the Corrupt screen is visable
staticCorrupt.Transparency = 1
imageLableCorrupt.ImageTransparency = 1
trigger.CanTouch = false
wait(10) ---How long before the trigger can be touched agian
trigger.CanTouch = true
triggerEnabled = true
end
end
end
trigger.Touched:Connect(touched) |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | function onRunning(speed)
if isSeated then return end
if speed>0 then
pose = "Running"
else
pose = "Standing"
end
end
function onDied()
pose = "Dead"
end
function onJumping()
isSeated = false
pose = "Jumping"
end
function onClimbing()
pose = "Climbing"
end
function onGettingUp()
pose = "GettingUp"
end
function onFreeFall()
pose = "FreeFall"
end
function onFallingDown()
pose = "FallingDown"
end
function onSeated()
isSeated = true
pose = "Seated"
print("Seated")
end
function moveJump()
RightShoulder.MaxVelocity = 0.5
LeftShoulder.MaxVelocity = 0.5
RightShoulder.DesiredAngle = 3.14
LeftShoulder.DesiredAngle = -3.14
RightHip.DesiredAngle = 0
LeftHip.DesiredAngle = 0
end
function moveFreeFall()
RightShoulder.MaxVelocity = 0.5
LeftShoulder.MaxVelocity = 0.5
RightShoulder.DesiredAngle = 1
LeftShoulder.DesiredAngle = -1
RightHip.DesiredAngle = 0
LeftHip.DesiredAngle = 0
end
function moveClimb()
RightShoulder.MaxVelocity = 0.5
LeftShoulder.MaxVelocity = 0.5
RightShoulder.DesiredAngle = -3.14
LeftShoulder.DesiredAngle = 3.14
RightHip.DesiredAngle = 0
LeftHip.DesiredAngle = 0
end
function moveSit()
print("Move Sit")
RightShoulder.MaxVelocity = 0.15
LeftShoulder.MaxVelocity = 0.15
RightShoulder.DesiredAngle = 3.14 /2
LeftShoulder.DesiredAngle = -3.14 /2
RightHip.DesiredAngle = 3.14 /2
LeftHip.DesiredAngle = -3.14 /2
end
function getTool()
kidTable = Figure:children()
if (kidTable ~= nil) then
numKids = #kidTable
for i=1,numKids do
if (kidTable[i].className == "Tool") then return kidTable[i] end
end
end
return nil
end
function getToolAnim(tool)
c = tool:children()
for i=1,#c do
if (c[i].Name == "toolanim" and c[i].className == "StringValue") then
return c[i]
end
end
return nil
end
function animateTool()
if (toolAnim == "None") then
RightShoulder.DesiredAngle = 1.57
return
end
if (toolAnim == "Slash") then
RightShoulder.MaxVelocity = 0.5
RightShoulder.DesiredAngle = 0
return
end
if (toolAnim == "Lunge") then
RightShoulder.MaxVelocity = 0.5
LeftShoulder.MaxVelocity = 0.5
RightHip.MaxVelocity = 0.5
LeftHip.MaxVelocity = 0.5
RightShoulder.DesiredAngle = 1.57
LeftShoulder.DesiredAngle = 1.0
RightHip.DesiredAngle = 1.57
LeftHip.DesiredAngle = 1.0
return
end
end
function move(time)
local amplitude
local frequency
if (pose == "Jumping") then
moveJump()
return
end
if (pose == "FreeFall") then
moveFreeFall()
return
end
if (pose == "Climbing") then
moveClimb()
return
end
if (pose == "Seated") then
moveSit()
return
end
RightShoulder.MaxVelocity = 0.15
LeftShoulder.MaxVelocity = 0.15
if (pose == "Running") then
amplitude = 1
frequency = 9
else
amplitude = 0.1
frequency = 1
end
desiredAngle = amplitude * math.sin(time*frequency)
RightShoulder.DesiredAngle = desiredAngle
LeftShoulder.DesiredAngle = desiredAngle
RightHip.DesiredAngle = -desiredAngle
LeftHip.DesiredAngle = -desiredAngle
local tool = getTool()
if tool ~= nil then
animStringValueObject = getToolAnim(tool)
if animStringValueObject ~= nil then
toolAnim = animStringValueObject.Value
-- message recieved, delete StringValue
animStringValueObject.Parent = nil
toolAnimTime = time + .3
end
if time > toolAnimTime then
toolAnimTime = 0
toolAnim = "None"
end
animateTool()
else
toolAnim = "None"
toolAnimTime = 0
end
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | --
function DPad:Enable()
DPadFrame.Visible = true
end
function DPad:Disable()
DPadFrame.Visible = false
OnInputEnded()
end
function DPad:Create(parentFrame)
if DPadFrame then
DPadFrame:Destroy()
DPadFrame = nil
end
local position = UDim2.new(0, 10, 1, -230)
DPadFrame = Instance.new('Frame')
DPadFrame.Name = "DPadFrame"
DPadFrame.Active = true
DPadFrame.Visible = false
DPadFrame.Size = UDim2.new(0, 192, 0, 192)
DPadFrame.Position = position
DPadFrame.BackgroundTransparency = 1
local smArrowSize = UDim2.new(0, 23, 0, 23)
local lgArrowSize = UDim2.new(0, 64, 0, 64)
local smImgOffset = Vector2.new(46, 46)
local lgImgOffset = Vector2.new(128, 128)
local bBtn = createArrowLabel("BackButton", UDim2.new(0.5, -32, 1, -64), lgArrowSize, Vector2.new(0, 0), lgImgOffset)
local fBtn = createArrowLabel("ForwardButton", UDim2.new(0.5, -32, 0, 0), lgArrowSize, Vector2.new(0, 258), lgImgOffset)
local lBtn = createArrowLabel("LeftButton", UDim2.new(0, 0, 0.5, -32), lgArrowSize, Vector2.new(129, 129), lgImgOffset)
local rBtn = createArrowLabel("RightButton", UDim2.new(1, -64, 0.5, -32), lgArrowSize, Vector2.new(0, 129), lgImgOffset)
local jumpBtn = createArrowLabel("JumpButton", UDim2.new(0.5, -32, 0.5, -32), lgArrowSize, Vector2.new(129, 0), lgImgOffset)
local flBtn = createArrowLabel("ForwardLeftButton", UDim2.new(0, 35, 0, 35), smArrowSize, Vector2.new(129, 258), smImgOffset)
local frBtn = createArrowLabel("ForwardRightButton", UDim2.new(1, -55, 0, 35), smArrowSize, Vector2.new(176, 258), smImgOffset)
flBtn.Visible = false
frBtn.Visible = false
-- input connections
jumpBtn.InputBegan:connect(function(inputObject)
MasterControl:DoJump()
end)
local movementVector = Vector3.new(0,0,0)
local function normalizeDirection(inputPosition)
local jumpRadius = jumpBtn.AbsoluteSize.x/2
local centerPosition = getCenterPosition()
local direction = Vector2.new(inputPosition.x - centerPosition.x, inputPosition.y - centerPosition.y)
if direction.magnitude > jumpRadius then
local angle = ATAN2(direction.y, direction.x)
local octant = (FLOOR(8 * angle / (2 * PI) + 8.5)%8) + 1
movementVector = COMPASS_DIR[octant]
end
if not flBtn.Visible and movementVector == COMPASS_DIR[7] then
flBtn.Visible = true
frBtn.Visible = true
end
end
DPadFrame.InputBegan:connect(function(inputObject)
if TouchObject or inputObject.UserInputType ~= Enum.UserInputType.Touch then
return
end
MasterControl:AddToPlayerMovement(-movementVector)
TouchObject = inputObject
normalizeDirection(TouchObject.Position)
MasterControl:AddToPlayerMovement(movementVector)
end)
DPadFrame.InputChanged:connect(function(inputObject)
if inputObject == TouchObject then
MasterControl:AddToPlayerMovement(-movementVector)
normalizeDirection(TouchObject.Position)
MasterControl:AddToPlayerMovement(movementVector)
end
end)
OnInputEnded = function()
TouchObject = nil
flBtn.Visible = false
frBtn.Visible = false
MasterControl:AddToPlayerMovement(-movementVector)
movementVector = Vector3.new(0, 0, 0)
end
DPadFrame.InputEnded:connect(function(inputObject)
if inputObject == TouchObject then
OnInputEnded()
end
end)
DPadFrame.Parent = parentFrame
end
return DPad |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | script.Parent:WaitForChild("A-Chassis Interface")
script.Parent:WaitForChild("Plugins")
script.Parent:WaitForChild("README")
local car=script.Parent.Parent
local _Tune=require(script.Parent)
wait(_Tune.LoadDelay)
--Weight Scaling
local weightScaling = _Tune.WeightScaling
if not workspace:PGSIsEnabled() then
weightScaling = _Tune.LegacyScaling
end
local Drive=car.Wheels:GetChildren()
--Remove Existing Mass
function DReduce(p)
for i,v in pairs(p:GetChildren())do
if v:IsA("BasePart") then
if v.CustomPhysicalProperties == nil then v.CustomPhysicalProperties = PhysicalProperties.new(v.Material) end
v.CustomPhysicalProperties = PhysicalProperties.new(
0,
v.CustomPhysicalProperties.Friction,
v.CustomPhysicalProperties.Elasticity,
v.CustomPhysicalProperties.FrictionWeight,
v.CustomPhysicalProperties.ElasticityWeight
)
end
DReduce(v)
end
end
DReduce(car) |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | game:GetService("Players").LocalPlayer.Chatted:connect(function(msg)
local emote = ""
if (string.sub(msg, 1, 3) == "/e ") then
emote = string.sub(msg, 4)
elseif (string.sub(msg, 1, 7) == "/emote ") then
emote = string.sub(msg, 8)
end
if (pose == "Standing" and emoteNames[emote] ~= nil) then
playAnimation(emote, 0.1, Humanoid)
end
end) |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | function Receive(player, action, ...)
local args = {...}
if player == User and action == "play" then
Connector:FireAllClients("play", User, args[1], Settings.SoundSource.Position, Settings.PianoSoundRange, Settings.PianoSounds, args[2], Settings.IsCustom)
HighlightPianoKey((args[1] > 61 and 61) or (args[1] < 1 and 1) or args[1],args[3])
elseif player == User and action == "abort" then
Deactivate()
if SeatWeld then
SeatWeld:remove()
end
end
end
function Activate(player)
Connector:FireClient(player, "activate", Settings.CameraCFrame, Settings.PianoSounds, true)
User = player
end
function Deactivate()
if User and User.Parent then
Connector:FireClient(User, "deactivate")
User.Character:SetPrimaryPartCFrame(Box.CFrame + Vector3.new(0, 5, 0))
end
User = nil
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local function GetTeamFromColor(teamColor)
for _, team in ipairs(Teams:GetTeams()) do
if team.TeamColor == teamColor then
return team
end
end
return nil
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | WindShake:SetDefaultSettings(WindShakeSettings)
WindShake:Init()
for _, ShakeObject in pairs(game.Workspace:GetDescendants()) do
if ShakeObject:IsA("BasePart") then
if table.find(ShakableObjects, ShakeObject.Name) then
WindShake:AddObjectShake(ShakeObject, WindShakeSettings)
end
end
end
game.Workspace.DescendantAdded:Connect(function(Object)
if table.find(ShakableObjects, Object.Name) then
WindShake:AddObjectShake(Object, WindShakeSettings)
end
end) |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | function GoTo(Target)
Path:ComputeAsync(NPC.HumanoidRootPart.Position, Target)
if Path.Status == Enum.PathStatus.NoPath then
else
local WayPoints = Path:GetWaypoints()
for _, WayPoint in ipairs(WayPoints) do
NPC.Humanoid:MoveTo(WayPoint.Position)
if WayPoint.Action == Enum.PathWaypointAction.Jump then
NPC.Humanoid.Jump = true
end
end
end
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | camera.Changed:connect(function()
local dis = (game.Lighting:GetSunDirection()-camera.CoordinateFrame.lookVector).magnitude
local parts = camera:GetPartsObscuringTarget({camera.CoordinateFrame,game.Lighting:GetSunDirection()*10000},{((camera.CoordinateFrame.p-player.Character.Head.Position).magnitude < 1 and player.Character or nil)})
if dis > 1 then dis = 1 end
for i = 1,#parts do
if parts[i] then
dis = 1
break
end
end
ts:Create(blind,TweenInfo.new(0.5,Enum.EasingStyle.Sine,Enum.EasingDirection.Out,0,false,0),{
Brightness = (1-dis)*0.35
}):Play()
ts:Create(blur,TweenInfo.new(0.5,Enum.EasingStyle.Sine,Enum.EasingDirection.Out,0,false,0),{
Size = 15*(1-dis)
}):Play()
end) |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local k = 0.5
local lowerK = 0.9
local function SCurveTransform(t)
t = math.clamp(t, -1,1)
if t >= 0 then
return (k*t) / (k - t + 1)
end
return -((lowerK*-t) / (lowerK + t + 1))
end
local DEADZONE = 0.25
local function toSCurveSpace(t)
return (1 + DEADZONE) * (2*math.abs(t) - 1) - DEADZONE
end
local function fromSCurveSpace(t)
return t/2 + 0.5
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local methods = {}
methods.__index = methods
local function CreateGuiObjects()
local BaseFrame = Instance.new("Frame")
BaseFrame.Selectable = false
BaseFrame.Size = UDim2.new(1, 0, 1, 0)
BaseFrame.BackgroundTransparency = 1
local Scroller = Instance.new("ScrollingFrame")
Scroller.Selectable = ChatSettings.GamepadNavigationEnabled
Scroller.Name = "Scroller"
Scroller.BackgroundTransparency = 1
Scroller.BorderSizePixel = 0
Scroller.Position = UDim2.new(0, 0, 0, 3)
Scroller.Size = UDim2.new(1, -4, 1, -6)
Scroller.CanvasSize = UDim2.new(0, 0, 0, 0)
Scroller.ScrollBarThickness = module.ScrollBarThickness
Scroller.Active = false
Scroller.Parent = BaseFrame
local Layout = Instance.new("UIListLayout")
Layout.SortOrder = Enum.SortOrder.LayoutOrder
Layout.Parent = Scroller
return BaseFrame, Scroller, Layout
end
function methods:Destroy()
self.GuiObject:Destroy()
self.Destroyed = true
end
function methods:SetActive(active)
self.GuiObject.Visible = active
end
function methods:UpdateMessageFiltered(messageData)
local messageObject = nil
local searchIndex = 1
local searchTable = self.MessageObjectLog
while (#searchTable >= searchIndex) do
local obj = searchTable[searchIndex]
if obj.ID == messageData.ID then
messageObject = obj
break
end
searchIndex = searchIndex + 1
end
if messageObject then
messageObject.UpdateTextFunction(messageData)
self:PositionMessageLabelInWindow(messageObject, searchIndex)
end
end
function methods:AddMessage(messageData)
self:WaitUntilParentedCorrectly()
local messageObject = MessageLabelCreator:CreateMessageLabel(messageData, self.CurrentChannelName)
if messageObject == nil then
return
end
table.insert(self.MessageObjectLog, messageObject)
self:PositionMessageLabelInWindow(messageObject, #self.MessageObjectLog)
end
function methods:AddMessageAtIndex(messageData, index)
local messageObject = MessageLabelCreator:CreateMessageLabel(messageData, self.CurrentChannelName)
if messageObject == nil then
return
end
table.insert(self.MessageObjectLog, index, messageObject)
self:PositionMessageLabelInWindow(messageObject, index)
end
function methods:RemoveLastMessage()
self:WaitUntilParentedCorrectly()
local lastMessage = self.MessageObjectLog[1]
lastMessage:Destroy()
table.remove(self.MessageObjectLog, 1)
end
function methods:IsScrolledDown()
local yCanvasSize = self.Scroller.CanvasSize.Y.Offset
local yContainerSize = self.Scroller.AbsoluteWindowSize.Y
local yScrolledPosition = self.Scroller.CanvasPosition.Y
return (yCanvasSize < yContainerSize or
yCanvasSize - yScrolledPosition <= yContainerSize + 5)
end
function methods:UpdateMessageTextHeight(messageObject)
local baseFrame = messageObject.BaseFrame
for i = 1, 10 do
if messageObject.BaseMessage.TextFits then
break
end
local trySize = self.Scroller.AbsoluteSize.X - i
baseFrame.Size = UDim2.new(1, 0, 0, messageObject.GetHeightFunction(trySize))
end
end
function methods:PositionMessageLabelInWindow(messageObject, index)
self:WaitUntilParentedCorrectly()
local wasScrolledDown = self:IsScrolledDown()
local baseFrame = messageObject.BaseFrame
local layoutOrder = 1
if self.MessageObjectLog[index - 1] then
if index == #self.MessageObjectLog then
layoutOrder = self.MessageObjectLog[index - 1].BaseFrame.LayoutOrder + 1
else
layoutOrder = self.MessageObjectLog[index - 1].BaseFrame.LayoutOrder
end
end
baseFrame.LayoutOrder = layoutOrder
baseFrame.Size = UDim2.new(1, 0, 0, messageObject.GetHeightFunction(self.Scroller.AbsoluteSize.X))
baseFrame.Parent = self.Scroller
if messageObject.BaseMessage then
self:UpdateMessageTextHeight(messageObject)
end
if wasScrolledDown then
self.Scroller.CanvasPosition = Vector2.new(
0, math.max(0, self.Scroller.CanvasSize.Y.Offset - self.Scroller.AbsoluteSize.Y))
end
end
function methods:ReorderAllMessages()
self:WaitUntilParentedCorrectly()
--// Reordering / reparenting with a size less than 1 causes weird glitches to happen
-- with scrolling as repositioning happens.
if self.GuiObject.AbsoluteSize.Y < 1 then return end
local oldCanvasPositon = self.Scroller.CanvasPosition
local wasScrolledDown = self:IsScrolledDown()
for _, messageObject in pairs(self.MessageObjectLog) do
self:UpdateMessageTextHeight(messageObject)
end
if not wasScrolledDown then
self.Scroller.CanvasPosition = oldCanvasPositon
else
self.Scroller.CanvasPosition = Vector2.new(
0, math.max(0, self.Scroller.CanvasSize.Y.Offset - self.Scroller.AbsoluteSize.Y))
end
end
function methods:Clear()
for _, v in pairs(self.MessageObjectLog) do
v:Destroy()
end
self.MessageObjectLog = {}
end
function methods:SetCurrentChannelName(name)
self.CurrentChannelName = name
end
function methods:FadeOutBackground(duration)
--// Do nothing
end
function methods:FadeInBackground(duration)
--// Do nothing
end
function methods:FadeOutText(duration)
for i = 1, #self.MessageObjectLog do
if self.MessageObjectLog[i].FadeOutFunction then
self.MessageObjectLog[i].FadeOutFunction(duration, CurveUtil)
end
end
end
function methods:FadeInText(duration)
for i = 1, #self.MessageObjectLog do
if self.MessageObjectLog[i].FadeInFunction then
self.MessageObjectLog[i].FadeInFunction(duration, CurveUtil)
end
end
end
function methods:Update(dtScale)
for i = 1, #self.MessageObjectLog do
if self.MessageObjectLog[i].UpdateAnimFunction then
self.MessageObjectLog[i].UpdateAnimFunction(dtScale, CurveUtil)
end
end
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | if year == 2007 then
script.Parent.ClickToChat.TextColor3 = Color3.new(0, 0, 0)
script.Parent.ChatBar.BackgroundColor3 = Color3.new(255/255, 255/255, 255/255)
end
local Chat = {
ChatColors = {
BrickColor.new("Bright red"),
BrickColor.new("Bright blue"),
BrickColor.new("Earth green"),
BrickColor.new("Bright violet"),
BrickColor.new("Bright orange"),
BrickColor.new("Bright yellow"),
BrickColor.new("Light reddish violet"),
BrickColor.new("Brick yellow"),
};
Gui = nil,
Frame = nil,
RenderFrame = nil,
TapToChatLabel = nil,
ClickToChatButton = nil,
Templates = nil,
EventListener = nil,
MessageQueue = {},
Configuration = {
FontSize = Enum.FontSize.Size12,
NumFontSize = 12,
HistoryLength = 20,
Size = UDim2.new(0.38, 0, 0.20, 0),
MessageColor = Color3.new(1, 1, 1),
AdminMessageColor = Color3.new(1, 215/255, 0),
XScale = 0.025,
LifeTime = 45,
Position = UDim2.new(0, 2, 0.05, 0),
DefaultTweenSpeed = 0.15,
};
CachedSpaceStrings_List = {},
Messages_List = {},
MessageThread = nil,
TempSpaceLabel = nil,
}
function GetNameValue(pName)
local value = 0
for index = 1, #pName do
local cValue = string.byte(string.sub(pName, index, index))
local reverseIndex = #pName - index + 1
if #pName%2 == 1 then
reverseIndex = reverseIndex - 1
end
if reverseIndex%4 >= 2 then
cValue = -cValue
end
value = value + cValue
end
return value%8
end
function Chat:ComputeChatColor(pName)
return self.ChatColors[GetNameValue(pName) + 1].Color
end
function Chat:UpdateQueue(field, diff)
for i = #self.MessageQueue, 1, -1 do
if self.MessageQueue[i] then
for _, label in pairs(self.MessageQueue[i]) do
if label and type(label) ~= "table" and type(label) ~= "number" then
if label:IsA("TextLabel") or label:IsA("TextButton") then
if diff then
label.Position = label.Position - UDim2.new(0, 0, diff, 0)
else
if field == self.MessageQueue[i] then
label.Position = UDim2.new(self.Configuration.XScale, 0, label.Position.Y.Scale - field["Message"].Size.Y.Scale , 0)
else
label.Position = UDim2.new(self.Configuration.XScale, 0, label.Position.Y.Scale - field["Message"].Size.Y.Scale, 0)
end
if label.Position.Y.Scale < -0.01 then
label.Visible = false
label:Destroy()
end
end
end
end
end
end
end
end
function Chat:ComputeSpaceString(pLabel)
local nString = " "
if not self.TempSpaceLabel then
self.TempSpaceLabel = self.Templates.SpaceButton
self.TempSpaceLabel.Size = UDim2.new(0, pLabel.AbsoluteSize.X, 0, pLabel.AbsoluteSize.Y);
end
self.TempSpaceLabel.Text = nString
while self.TempSpaceLabel.TextBounds.X < pLabel.TextBounds.X do
nString = nString .. " "
self.TempSpaceLabel.Text = nString
end
nString = nString .. " "
self.CachedSpaceStrings_List[pLabel.Text] = nString
self.TempSpaceLabel.Text = ""
return nString
end
function Chat:UpdateChat(cPlayer, message)
local messageField = {["Player"] = cPlayer,["Message"] = message}
if coroutine.status(Chat.MessageThread) == "dead" then
table.insert(Chat.Messages_List, messageField)
Chat.MessageThread = coroutine.create(function ()
for i = 1, #Chat.Messages_List do
local field = Chat.Messages_List[i]
Chat:CreateMessage(field["Player"], field["Message"])
end
Chat.Messages_List = {}
end)
coroutine.resume(Chat.MessageThread)
else
table.insert(Chat.Messages_List, messageField)
end
end
function Chat:CreateMessage(cPlayer, message)
local pName = cPlayer ~= nil and cPlayer.Name or "GAME"
message = message:gsub("^%s*(.-)%s*$", "%1")
self.MessageQueue[#self.MessageQueue] = (#self.MessageQueue > self.Configuration.HistoryLength) and nil or self.MessageQueue[#self.MessageQueue]
local pLabel = self.Templates.pLabel:clone()
pLabel.Name = pName;
pLabel.Text = pName .. ";";
pLabel.Parent = self.RenderFrame;
pLabel.TextColor3 = (cPlayer.Neutral) and Chat:ComputeChatColor(pName) or cPlayer.TeamColor.Color
local nString = self.CachedSpaceStrings_List[pName] or Chat:ComputeSpaceString(pLabel)
local mLabel = self.Templates.mLabel:clone()
mLabel.Name = pName .. " - message";
mLabel.TextColor3 = Chat.Configuration.MessageColor;
mLabel.Text = nString .. message;
mLabel.Parent = self.RenderFrame;
local heightField = mLabel.TextBounds.Y
mLabel.Size = UDim2.new(1, 0, heightField/self.RenderFrame.AbsoluteSize.Y, 0)
pLabel.Size = mLabel.Size
local yPixels = self.RenderFrame.AbsoluteSize.Y
local yFieldSize = mLabel.TextBounds.Y
local queueField = {}
queueField["Player"] = pLabel
queueField["Message"] = mLabel
queueField["SpawnTime"] = tick()
table.insert(self.MessageQueue, 1, queueField)
Chat:UpdateQueue(queueField)
end
function Chat:CreateChatBar()
self.ClickToChatButton = self.Gui:WaitForChild("ClickToChat")
self.ChatBar = self.Gui:WaitForChild("ChatBar")
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.KeyDown:connect(function (key)
if key:byte() == 47 or key == "/" then
self.ClickToChatButton.Visible = false
if year > 2007 then
self.ChatBar.BackgroundColor3 = Color3.new(255/255, 255/255, 255/255)
end
self.ChatBar:CaptureFocus()
end
end)
self.ClickToChatButton.MouseButton1Click:connect(function ()
self.ClickToChatButton.Visible = false
if year > 2007 then
self.ChatBar.BackgroundColor3 = Color3.new(255/255, 255/255, 255/255)
end
self.ChatBar:CaptureFocus()
end)
end
function Chat:PlayerChat(message)
local m = Instance.new("StringValue")
m.Name = "NewMessage"
m.Value = message
m.Parent = game.Players.LocalPlayer
game:GetService("Debris"):AddItem(m, 2)
end
function Chat:CreateGui()
self.Gui = script.Parent
self.Frame = self.Gui:WaitForChild("ChatFrame")
self.RenderFrame = self.Frame:WaitForChild("ChatRenderFrame")
self.Templates = self.Gui:WaitForChild("Templates")
Chat:CreateChatBar()
self.ChatBar.FocusLost:connect(function(enterPressed)
if year > 2007 then
self.ChatBar.BackgroundColor3 = Color3.new(64/255, 64/255, 64/255)
end
if enterPressed and self.ChatBar.Text ~= "" then
local cText = self.ChatBar.Text
if string.sub(self.ChatBar.Text, 1, 1) == "%" then
cText = "(TEAM) " .. string.sub(cText, 2, #cText)
end
Chat:PlayerChat(cText)
if self.ClickToChatButton then
self.ClickToChatButton.Visible = true
end
self.ChatBar.Text = ""
self.ClickToChatButton.Visible = true
end
end)
end
function Chat:TrackPlayerChats()
local function chatRegister(p)
p.ChildAdded:connect(function (obj)
if obj:IsA("StringValue") and obj.Name == "NewMessage" then
if game.Players.LocalPlayer.Neutral or p.TeamColor == game.Players.LocalPlayer.TeamColor then
Chat:UpdateChat(p, obj.Value)
end
end
end)
end
for _,v in pairs(game.Players:GetPlayers()) do
chatRegister(v)
end
game.Players.PlayerAdded:connect(chatRegister)
end
function Chat:CullThread()
Spawn(function ()
while true do
if #self.MessageQueue > 0 then
for _, field in pairs(self.MessageQueue) do
if field["SpawnTime"] and field["Player"] and field["Message"] and tick() - field["SpawnTime"] > self.Configuration.LifeTime then
field["Player"].Visible = false
field["Message"].Visible = false
end
end
end
wait(5)
end
end)
end
function Chat:Initialize()
Chat:CreateGui()
Chat:TrackPlayerChats()
self.MessageThread = coroutine.create(function () end)
coroutine.resume(self.MessageThread)
Chat:CullThread()
end
Chat:Initialize() |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | if backfire == true then
mouse.KeyDown:connect(function(key)
if key == camkey and enabled == false then
local children = car.Body.Exhaust:GetChildren()
for index, child in pairs(children) do
if child.Name == "Backfire1" or child.Name == "Backfire2" then
local effect = script.soundeffect:Clone()
local effect2 = script.soundeffect:Clone()
effect.Name = "soundeffectCop"
effect2.Name = "soundeffectCop"
effect.Parent = child.Backfire1
effect2.Parent = child.Backfire2
end
end
elseif key == camkey and enabled == true then
local children = car.Body.Exhaust2:GetChildren()
for index, child in pairs(children) do
if child.Name == "Backfire1" or child.Name == "Backfire2" then
child.Backfire1.soundeffectCop:Destroy()
child.Backfire2.soundeffectCop:Destroy()
end
end
end
car.DriveSeat.ChildRemoved:Connect(function(child)
if child.Name == "SeatWeld" then
local descendants = car.Body.Exhaust2:GetDescendants()
for index, descendant in pairs(descendants) do
if descendant.Name == "soundeffectCop" then
descendant:Destroy()
end
end
end
end)
end)
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local MovementMap = {
[Enum.KeyCode.W] = Vector3.new(0, 0, -1);
[Enum.KeyCode.A] = Vector3.new(-1, 0, 0);
[Enum.KeyCode.S] = Vector3.new(0, 0, 1);
[Enum.KeyCode.D] = Vector3.new(1, 0, 0)
}
local Maid
local MovementController = {}
function MovementController:GetInput()
local totalVector = Vector3.new()
local isJump
local allKeys = UserInputService:GetKeysPressed()
for _, key in pairs(allKeys) do
if (MovementMap[key.KeyCode]) then
totalVector += MovementMap[key.KeyCode]
elseif (key.KeyCode == Enum.KeyCode.Space) then
isJump = true
end
end
local CameraCF = Camera.CFrame
local X, Y, Z = CameraCF:ToOrientation()
local newCF = CFrame.Angles(0, Y, Z)
local FinalVector = newCF:VectorToWorldSpace(totalVector)
RobloxianController:TellControl(FinalVector, isJump, newCF.LookVector)
end
function MovementController:Deactivate()
Maid:Destroy()
end
function MovementController:Activate()
Maid._InputCon = RunService.RenderStepped:Connect(function()
self:GetInput()
end)
end
function MovementController:Start()
RobloxianController = self.Controllers.RobloxianController
Maid = self.Shared.Maid.new()
end
function MovementController:Init()
end
return MovementController |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | function Promise:Yield()
if self._fulfilled then
return true, unpack(self._fulfilled, 1, self._valuesLength)
elseif self._rejected then
return false, unpack(self._rejected, 1, self._valuesLength)
else
local bindable = Instance.new("BindableEvent")
self:Then(function()
bindable:Fire()
end, function()
bindable:Fire()
end)
bindable.Event:Wait()
bindable:Destroy()
if self._fulfilled then
return true, unpack(self._fulfilled, 1, self._valuesLength)
elseif self._rejected then
return false, unpack(self._rejected, 1, self._valuesLength)
end
end
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | function onClicked()
Option()
end
script.Parent.MouseButton1Down:connect (onClicked) |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | function Janitor.__index:Add(Object, MethodName, Index)
if Index then
self:Remove(Index)
local This = self[IndicesReference]
if not This then
This = {}
self[IndicesReference] = This
end
This[Index] = Object
end
MethodName = MethodName or TypeDefaults[typeof(Object)] or "Destroy"
if type(Object) ~= "function" and not Object[MethodName] then
warn(string.format(METHOD_NOT_FOUND_ERROR, tostring(Object), tostring(MethodName), debug.traceback(nil :: any, 2)))
end
self[Object] = MethodName
return Object
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local function GetAnimationFromChord(chord: number, hold: boolean): Animation
if hold then
return AnimationsDB.Sustain
end
if chord == 1 then
return AnimationsDB.SpecialA
elseif chord == 2 then
return AnimationsDB.SpecialB
elseif chord == 3 then
return AnimationsDB.SpecialC
end
return AnimationsDB.SpecialD
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | if BlockPosition == 1 then
Block.CFrame = Pos1
end
if BlockPosition == 2 then
Block.CFrame = Pos2
end
if BlockPosition == 3 then
Block.CFrame = Pos3
end
if BlockPosition == 4 then
Block.CFrame = Pos4
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | Zombie.Humanoid.Died:Connect(function()
script.Parent:Destroy()
end)
Zombie.Humanoid.HealthChanged:Connect(function()
Zombie.Damage = math.ceil((script.Parent.Humanoid.Health * 1.2) / 2)
end) |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | mouse.KeyDown:connect(function(key)
if key=="m" then
veh.Lightbar.middle.Beep:Play()
veh.Lightbar.Remotes.AllyEvent:FireServer(true)
end
end) |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local plr = script.Parent.Parent.Parent
local autoclick = false
local autoclickDD = false
function GetAuto()
game.Workspace.Tree.Size = game.Workspace.Tree.Size + Vector3.new(1,1,1)
game.Workspace.Base.Size = game.Workspace.Base.Size + Vector3.new(1,0,1)
game.Workspace.Pop:Play()
end
script.Parent.AutoClick.MouseButton1Click:Connect(function()
if autoclick == false then
autoclick = true
script.Parent.AutoClick.Text = "ON"
else
autoclick = false
script.Parent.AutoClick.Text = "OFF"
end
end)
while wait()do
if autoclick == true then
if autoclickDD == false then
autoclickDD = true
GetAuto(1)-- Cambia El Tiempo De Espera Al Recargar
wait(0)-- Tambien Cambia Para El Tiempo De Espera Al Recargar
autoclickDD = false
end
end
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | while game:GetService("RunService").Heartbeat:wait() and car:FindFirstChild("DriveSeat") and character.Humanoid.SeatPart == car.DriveSeat do
--game:GetService("RunService").RenderStepped:wait()
if IsGrounded() then
if movement.Y ~= 0 then
local velocity = humanoidRootPart.CFrame.lookVector * movement.Y * stats.Speed.Value
humanoidRootPart.Velocity = humanoidRootPart.Velocity:Lerp(velocity, 0.1)
bodyVelocity.maxForce = Vector3.new(0, 0, 0)
else
bodyVelocity.maxForce = Vector3.new(mass / 2, mass / 4, mass / 2)
end
local rotVelocity = humanoidRootPart.CFrame:vectorToWorldSpace(Vector3.new(movement.Y * stats.Speed.Value / 50, 0, -humanoidRootPart.RotVelocity.Y * 5 * movement.Y))
local speed = -humanoidRootPart.CFrame:vectorToObjectSpace(humanoidRootPart.Velocity).unit.Z
rotation = rotation + math.rad((-stats.Speed.Value / 5) * movement.Y)
if math.abs(speed) > 0.1 then
rotVelocity = rotVelocity + humanoidRootPart.CFrame:vectorToWorldSpace((Vector3.new(0, -movement.X * speed * stats.TurnSpeed.Value, 0)))
bodyAngularVelocity.maxTorque = Vector3.new(0, 0, 0)
else
bodyAngularVelocity.maxTorque = Vector3.new(mass / 4, mass / 2, mass / 4)
end
humanoidRootPart.RotVelocity = humanoidRootPart.RotVelocity:Lerp(rotVelocity, 0.1)
--bodyVelocity.maxForce = Vector3.new(mass / 3, mass / 6, mass / 3)
--bodyAngularVelocity.maxTorque = Vector3.new(mass / 6, mass / 3, mass / 6)
else
bodyVelocity.maxForce = Vector3.new(0, 0, 0)
bodyAngularVelocity.maxTorque = Vector3.new(0, 0, 0)
end
for i, part in pairs(car:GetChildren()) do
if part.Name == "Thruster" then
UpdateThruster(part)
end
end
end
for i, v in pairs(car:GetChildren()) do
if v:FindFirstChild("BodyThrust") then
v.BodyThrust:Destroy()
end
end
bodyVelocity:Destroy()
bodyAngularVelocity:Destroy()
--camera.CameraType = oldCameraType
script:Destroy() |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | while true do
while Humanoid.Health < Humanoid.MaxHealth do
local dt = wait(REGEN_STEP)
local dh = dt*REGEN_RATE*Humanoid.MaxHealth
Humanoid.Health = math.min(Humanoid.Health + dh, Humanoid.MaxHealth)
end
Humanoid.HealthChanged:Wait()
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local function toggleWindow(button)
local windowName = button.Name
-- Find the corresponding frame in the AppManager using the window name
local window = gui:FindFirstChild(windowName)
if window then
if window.Visible == false then
-- Close other windows
for _, child in ipairs(gui:GetChildren()) do
if child:IsA("Frame") and child.Visible then
end
end
local startPos = UDim2.new(0.0, 0, 0.978, 0)
window.Position = startPos
-- Set the initial size of the window to be zero
window.Size = UDim2.new(1, 0, 0.022, 0)
-- Show the window and tween its position and size from the button position and size to its original position and size
window.Visible = true
window:TweenSizeAndPosition(
UDim2.new(1, 0, 0.806, 0),
UDim2.new(0, 0, 0.194, 0),
'Out',
'Quad',
0.2
)
end
end
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local maxChunkSize = 100 * 1000
local ApiJson
if script:FindFirstChild("RawApiJson") then
ApiJson = script.RawApiJson
else
ApiJson = ""
end
local jsonToParse = require(ApiJson)
function getRbxApi() |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | elseif sv.Value==5 then
while s.Pitch<1 do
s.Pitch=s.Pitch+0.010
s:Play()
if s.Pitch>1 then
s.Pitch=1
end
wait(-9)
end
while true do
for x = 1, 500 do
s:play()
wait(-9)
end
wait()
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | function Table.swapKeyValue(orig)
local tab = {}
for key, val in pairs(orig) do
tab[val] = key
end
return tab
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | function JsonToLocalizationTable.getOrCreateLocalizationTable()
local localizationTable = LocalizationService:FindFirstChild(LOCALIZATION_TABLE_NAME)
if not localizationTable then
localizationTable = Instance.new("LocalizationTable")
localizationTable.Name = LOCALIZATION_TABLE_NAME
if RunService:IsRunning() then
localizationTable.Parent = LocalizationService
end
end
return localizationTable
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | function ExternalEventConnection:render()
return Roact.oneChild(self.props[Roact.Children])
end
function ExternalEventConnection:didMount()
local event = self.props.event
local callback = self.props.callback
self.connection = event:Connect(callback)
end
function ExternalEventConnection:didUpdate(oldProps)
if self.props.event ~= oldProps.event or self.props.callback ~= oldProps.callback then
self.connection:Disconnect()
self.connection = self.props.event:Connect(self.props.callback)
end
end
function ExternalEventConnection:willUnmount()
self.connection:Disconnect()
self.connection = nil
end
return ExternalEventConnection |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | function ClientRemoteSignal:Connect(fn)
if self._directConnect then
return self._re.OnClientEvent:Connect(fn)
else
return self._signal:Connect(fn)
end
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | table.insert(animTable[name].connections, config.ChildAdded:connect(function(child) configureAnimationSet(name, fileList) end))
table.insert(animTable[name].connections, config.ChildRemoved:connect(function(child) configureAnimationSet(name, fileList) end))
local idx = 1
for _, childPart in pairs(config:GetChildren()) do
if (childPart:IsA("Animation")) then
table.insert(animTable[name].connections, childPart.Changed:connect(function(property) configureAnimationSet(name, fileList) end))
animTable[name][idx] = {}
animTable[name][idx].anim = childPart
local weightObject = childPart:FindFirstChild("Weight")
if (weightObject == nil) then
animTable[name][idx].weight = 1
else
animTable[name][idx].weight = weightObject.Value
end
animTable[name].count = animTable[name].count + 1
animTable[name].totalWeight = animTable[name].totalWeight + animTable[name][idx].weight
-- print(name .. " [" .. idx .. "] " .. animTable[name][idx].anim.AnimationId .. " (" .. animTable[name][idx].weight .. ")")
idx = idx + 1
end
end
end
-- fallback to defaults
if (animTable[name].count <= 0) then
for idx, anim in pairs(fileList) do
animTable[name][idx] = {}
animTable[name][idx].anim = Instance.new("Animation")
animTable[name][idx].anim.Name = name
animTable[name][idx].anim.AnimationId = anim.id
animTable[name][idx].weight = anim.weight
animTable[name].count = animTable[name].count + 1
animTable[name].totalWeight = animTable[name].totalWeight + anim.weight |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | function TestPlan:addRoot(path, method)
local curNode = self
for i = #path, 1, -1 do
local nextNode = nil
for _, child in ipairs(curNode.children) do
if child.phrase == path[i] then
nextNode = child
break
end
end
if nextNode == nil then
nextNode = curNode:addChild(path[i], TestEnum.NodeType.Describe)
end
curNode = nextNode
end
curNode.callback = method
curNode:expand()
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local anim = animTable[animName][idx].anim
-- load it to the humanoid; get AnimationTrack
toolOldAnimTrack = toolAnimTrack
toolAnimTrack = humanoid:LoadAnimation(anim)
-- play the animation
toolAnimTrack:Play(transitionTime)
toolAnimName = animName
currentToolAnimKeyframeHandler = toolAnimTrack.KeyframeReached:connect(toolKeyFrameReachedFunc)
end
end
function stopToolAnimations()
local oldAnim = toolAnimName
if (currentToolAnimKeyframeHandler ~= nil) then
currentToolAnimKeyframeHandler:disconnect()
end
toolAnimName = ""
if (toolAnimTrack ~= nil) then
toolAnimTrack:Stop()
toolAnimTrack:Destroy()
toolAnimTrack = nil
end
return oldAnim
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | function Gamepad:GetHighestPriorityGamepad()
local connectedGamepads = UserInputService:GetConnectedGamepads()
local bestGamepad = NONE -- Note that this value is higher than all valid gamepad values
for _, gamepad in pairs(connectedGamepads) do
if gamepad.Value < bestGamepad.Value then
bestGamepad = gamepad
end
end
return bestGamepad
end
function Gamepad:BindContextActions()
if self.activeGamepad == NONE then
-- There must be an active gamepad to set up bindings
return false
end
local handleJumpAction = function(actionName, inputState, inputObject)
self.isJumping = (inputState == Enum.UserInputState.Begin)
return Enum.ContextActionResult.Sink
end
local handleThumbstickInput = function(actionName, inputState, inputObject)
if inputState == Enum.UserInputState.Cancel then
self.moveVector = ZERO_VECTOR3
return Enum.ContextActionResult.Sink
end
if self.activeGamepad ~= inputObject.UserInputType then
return Enum.ContextActionResult.Pass
end
if inputObject.KeyCode ~= Enum.KeyCode.Thumbstick1 then return end
if inputObject.Position.magnitude > thumbstickDeadzone then
self.moveVector = Vector3.new(inputObject.Position.X, 0, -inputObject.Position.Y)
else
self.moveVector = ZERO_VECTOR3
end
return Enum.ContextActionResult.Sink
end
ContextActionService:BindActivate(self.activeGamepad, Enum.KeyCode.ButtonR2)
ContextActionService:BindActionAtPriority("jumpAction", handleJumpAction, false,
self.CONTROL_ACTION_PRIORITY, Enum.KeyCode.ButtonA)
ContextActionService:BindActionAtPriority("moveThumbstick", handleThumbstickInput, false,
self.CONTROL_ACTION_PRIORITY, Enum.KeyCode.Thumbstick1)
return true
end
function Gamepad:UnbindContextActions()
if self.activeGamepad ~= NONE then
ContextActionService:UnbindActivate(self.activeGamepad, Enum.KeyCode.ButtonR2)
end
ContextActionService:UnbindAction("moveThumbstick")
ContextActionService:UnbindAction("jumpAction")
end
function Gamepad:OnNewGamepadConnected()
-- A new gamepad has been connected.
local bestGamepad: Enum.UserInputType = self:GetHighestPriorityGamepad()
if bestGamepad == self.activeGamepad then
-- A new gamepad was connected, but our active gamepad is not changing
return
end
if bestGamepad == NONE then
-- There should be an active gamepad when GamepadConnected fires, so this should not
-- normally be hit. If there is no active gamepad, unbind actions but leave
-- the module enabled and continue to listen for a new gamepad connection.
warn("Gamepad:OnNewGamepadConnected found no connected gamepads")
self:UnbindContextActions()
return
end
if self.activeGamepad ~= NONE then
-- Switching from one active gamepad to another
self:UnbindContextActions()
end
self.activeGamepad = bestGamepad
self:BindContextActions()
end
function Gamepad:OnCurrentGamepadDisconnected()
if self.activeGamepad ~= NONE then
ContextActionService:UnbindActivate(self.activeGamepad, Enum.KeyCode.ButtonR2)
end
local bestGamepad = self:GetHighestPriorityGamepad()
if self.activeGamepad ~= NONE and bestGamepad == self.activeGamepad then
warn("Gamepad:OnCurrentGamepadDisconnected found the supposedly disconnected gamepad in connectedGamepads.")
self:UnbindContextActions()
self.activeGamepad = NONE
return
end
if bestGamepad == NONE then
-- No active gamepad, unbinding actions but leaving gamepad connection listener active
self:UnbindContextActions()
self.activeGamepad = NONE
else
-- Set new gamepad as active and bind to tool activation
self.activeGamepad = bestGamepad
ContextActionService:BindActivate(self.activeGamepad, Enum.KeyCode.ButtonR2)
end
end
function Gamepad:ConnectGamepadConnectionListeners()
self.gamepadConnectedConn = UserInputService.GamepadConnected:Connect(function(gamepadEnum)
self:OnNewGamepadConnected()
end)
self.gamepadDisconnectedConn = UserInputService.GamepadDisconnected:Connect(function(gamepadEnum)
if self.activeGamepad == gamepadEnum then
self:OnCurrentGamepadDisconnected()
end
end)
end
function Gamepad:DisconnectGamepadConnectionListeners()
if self.gamepadConnectedConn then
self.gamepadConnectedConn:Disconnect()
self.gamepadConnectedConn = nil
end
if self.gamepadDisconnectedConn then
self.gamepadDisconnectedConn:Disconnect()
self.gamepadDisconnectedConn = nil
end
end
return Gamepad |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local function Truncate(tbl: Table, len: number): Table
local n = #tbl
len = math.clamp(len, 1, n)
if len == n then
return table.clone(tbl)
end
return table.move(tbl, 1, len, 1, table.create(len))
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | function Handler:add(hitboxObject)
assert(typeof(hitboxObject) ~= "Instance", "Make sure you are initializing from the Raycast module, not from this handler.")
table.insert(ActiveHitboxes, hitboxObject)
end
function Handler:remove(object)
for i in ipairs(ActiveHitboxes) do
if ActiveHitboxes[i].object == object then
ActiveHitboxes[i]:Destroy()
setmetatable(ActiveHitboxes[i], nil)
table.remove(ActiveHitboxes, i)
end
end
end
function Handler:check(object)
for _, hitbox in ipairs(ActiveHitboxes) do
if hitbox.object == object then
return hitbox
end
end
end
function OnTagRemoved(object)
Handler:remove(object)
end
CollectionService:GetInstanceRemovedSignal("RaycastModuleManaged"):Connect(OnTagRemoved) |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local hitPart = script.Parent
local debounce = true
local tool = game.ServerStorage.Floral -- Change "Sword" to the name of your tool, make sure your tool is in ServerStorage
hitPart.Touched:Connect(function(hit)
if debounce == true then
if hit.Parent:FindFirstChild("Humanoid") then
local plr = game.Players:FindFirstChild(hit.Parent.Name)
if plr then
debounce = false
hitPart.BrickColor = BrickColor.new("Bright red")
tool:Clone().Parent = plr.Backpack
wait(3) -- Change "3" to however long you want the player to have to wait before they can get the tool again
debounce = true
hitPart.BrickColor = BrickColor.new("Bright green")
end
end
end
end) |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | function Immutable.Append(list, ...)
local new = {}
local len = #list
for key = 1, len do
new[key] = list[key]
end
for i = 1, select("#", ...) do
new[len + i] = select(i, ...)
end
return new
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | local player=game.Players.LocalPlayer
local mouse=player:GetMouse()
local car = script.Parent.Parent.Car.Value
local _Tune = require(car["A-Chassis Tune"])
local gauges = script.Parent
local values = script.Parent.Parent.Values
local isOn = script.Parent.Parent.IsOn
gauges:WaitForChild("Speedo")
gauges:WaitForChild("Tach")
gauges:WaitForChild("Boost")
gauges:WaitForChild("ln")
gauges:WaitForChild("bln")
gauges:WaitForChild("Gear")
gauges:WaitForChild("Speed")
car.DriveSeat.HeadsUpDisplay = false
local _pRPM = _Tune.PeakRPM
local _lRPM = _Tune.Redline
if not _Tune.Engine and _Tune.Electric then _lRPM = _Tune.ElecRedline _pRPM = _Tune.ElecTransition2 end
local currentUnits = 1
local revEnd = math.ceil(_lRPM/1000) |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | debounce = true
function onTouched(hit)
if (hit.Parent:findFirstChild("Humanoid") ~= nil and debounce == true) then
debounce = false
h = Instance.new("Hat")
p = Instance.new("Part")
h.Name = "2006 Visor"
p.Parent = h
p.Position = hit.Parent:findFirstChild("Head").Position
p.Name = "Handle"
p.formFactor = 0
p.Size = Vector3.new(1, 1, 1)
p.BottomSurface = 0
p.TopSurface = 0
p.Locked = true
script.Parent.Mesh:clone().Parent = p
h.Parent = hit.Parent
h.AttachmentPos = Vector3.new(0, 0.09, 0.18)
wait(5)
debounce = true
end
end
script.Parent.Touched:connect(onTouched) |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | for i, channelData in pairs(initData.Channels) do
if channelData[1] == ChatSettings.GeneralChannelName then
HandleChannelJoined(channelData[1], channelData[2], channelData[3], channelData[4], true, false)
end
end
for i, channelData in pairs(initData.Channels) do
if channelData[1] ~= ChatSettings.GeneralChannelName then
HandleChannelJoined(channelData[1], channelData[2], channelData[3], channelData[4], true, false)
end
end
return moduleApiTable |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | --
function Path.new(agent, agentParameters, override)
if not (agent and agent:IsA("Model") and agent.PrimaryPart) then
output(error, "Pathfinding agent must be a valid Model Instance with a set PrimaryPart.")
end
local self = setmetatable({
_settings = override or DEFAULT_SETTINGS;
_events = {
Reached = Instance.new("BindableEvent");
WaypointReached = Instance.new("BindableEvent");
Blocked = Instance.new("BindableEvent");
Error = Instance.new("BindableEvent");
Stopped = Instance.new("BindableEvent");
};
_agent = agent;
_humanoid = agent:FindFirstChildOfClass("Humanoid");
_path = PathfindingService:CreatePath(agentParameters);
_status = "Idle";
_t = 0;
_position = {
_last = Vector3.new();
_count = 0;
};
}, Path)
--Configure settings
for setting, value in pairs(DEFAULT_SETTINGS) do
self._settings[setting] = self._settings[setting] == nil and value or self._settings[setting]
end
--Path blocked connection
self._path.Blocked:Connect(function(...)
if (self._currentWaypoint <= ... and self._currentWaypoint + 1 >= ...) and self._humanoid then
setJumpState(self)
self._events.Blocked:Fire(self._agent, self._waypoints[...])
end
end)
return self
end |
Explain this Roblox Luau script. | Source: Roblox/luau_corpus | function ObservableSubscriptionTable:Observe(key)
assert(key ~= nil, "Bad key")
return Observable.new(function(sub)
if not self._subMap[key] then
self._subMap[key] = { sub }
else
table.insert(self._subMap[key], sub)
end
return function()
if not self._subMap[key] then
return
end
local current = self._subMap[key]
local index = table.find(current, sub)
if not index then
return
end
table.remove(current, index)
if #current == 0 then
self._subMap[key] = nil
end
-- Complete the subscription
if sub:IsPending() then
task.spawn(function()
sub:Complete()
end)
end
end
end)
end |
End of preview. Expand in Data Studio
- Downloads last month
- 103