Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DevKing scripting
- Beginner's Roblox Scripting Tutorial #3 - Variables
- local Myname
- local HotDog = 4
- The variable is the word after the local
- like HotDog
- Beginner's Roblox Scripting Tutorial #4 - Arithmetic + Object-Oriented Programming
- print (10 + 10)
- --output will say 20
- local Baseplate = game.Workspace.Baseplate
- Baseplate.material ="Wood"
- if there is a check you need to say = true or false
- -- way to adjust properties
- Beginner's Roblox Scripting Tutorial #5 - Functions
- local function BestFunction()
- local best number = 10
- local worst number = 15
- print(BestNumber+Worst number)
- BestFunction()
- -- output will say 25
- Beginner's Roblox Scripting Tutorial #6 - Scope & Returning
- local a = 2
- local function Test1()
- print (a)
- end
- local function Test2()
- print (a)
- end
- Test1()
- Test2()
- --------------------------------------------------
- local function hi()
- print (hi)
- return "Awesome"
- end
- local Hotdog = hi()
- print(Hotdog)
- -- this will return awesome
- ----------------------------------------------
- function testReturn()
- return "This is a test!"
- end
- local returnedValue = testReturn() -- We've called the function, necessary for the functions to work.
- print(returnedValue)
- Beginner's Roblox Scripting Tutorial #7
- Beginner's Roblox Scripting Tutorial #8 - If Statements
- 3 types of if statements
- local x = 3
- if x == 3 then
- print ("Yes")
- end
- local x = 3
- local y = 9
- if x == 3 and y == 9 then
- print("Yes ")
- end
- local x = 2
- local y = 6
- if x == 3 or y == 6 then
- print("Yes ")
- -- it will print yes cuz 1 is correct
- local Baseplate = game.Workspace.Baseplate
- if Baseplate.Anchored == true then
- Baseplate.Anchored = false
- wait (2)
- Baseplate.Anchored = true
- end
- Beginner's Roblox Scripting Tutorial #9 - Else & Elseif Statements
- -- if the if statment is not true it will run a else statmente
- local Hotdogs = 3
- if Hotdogs == 3 then print ("Hotdogs is equal to 3")
- elseif
- print ("Hotdogs is not equal to 3")
- end
- Beginner's Roblox Scripting Tutorial #10 - Events
- game.Workspace.MyFavPart.Touched:Connect(function)
- -- this will see if somebody stepped on the part Touched:Connect is a way to connect the function
- Beginner's Roblox Scripting Tutorial #11 - Built-In Functions
- local melon = game.Workspace:FindFristChild("Hotdog")
- WaitForChild
- Beginner's Roblox Scripting Tutorial #12 - While and Repeat Loops
- this is a regular loop
- local hotdogs = 1
- while hotdogs < 5 do
- hotdogs = hotdogs + 1
- print ("Hello")
- print (hotdogs)
- end
- -- if hotdogs are less then five do something
- you need to do the hotdogs = hotdogs + 1 unless it will go in an infinite loop
- local hotdogs = 1
- while hotdogs < 5 do
- wait(1)
- print ("Hello")
- print (hotdogs)
- end
- local hotdogs = 1
- repeat
- ("This is from the loop")
- untile hotdogs == 3
- while hotdogs == 3 do
- print ("This is from the loop")
- end
- local hotdogs = 1
- repeat wait() until game.Players
- Beginner's Roblox Scripting Tutorial #14 - Instances
- local part = Instance.new("Part")
- part.Parent = game.Workspace
- Beginner's Roblox Scripting Tutorial #15 - Breaks / Loop Breaking
- local raindropped = 0
- while true do
- if raindropped >= 1000 then
- break
- end
- raindropped = raindropped +1
- wait()
- local Rain = Instance.new("Part",game.Workspace)
- Rain.Position = Vector3.new(0,500,5)
- Rain.Size = Vector3.new(1,1,1)
- Rain.Material = "Glass"
- Rain.Transparency = 0.50
- Rain.Touched:Connect(function(hit)
- if hit.Parent:FindFirstChild("Humanoid") then
- hit.Parent.Humanoid.Health = 0
- end
- end)
- end
- end
- Beginner's Roblox Scripting Tutorial #17 - Leaderboards / leaderstats
- game.Players.PlayerAdded:Connect(function(player)
- local leaderstats = Instance.new("Folder",player)
- leaderstats.Name = "leaderstats"
- local Points = Instance.new("IntValue, leaderstats")
- Points.Name = "Points"
- end)
- -- this is how to make a point giver
- script.Parent.ClickDector.MouseClick:Connect(function(player)
- local player Playerpoins = player.leaderstats.Points
- PlayerPoints.Value = PlayerPoints.Value + 1
- end)
- Beginner's Roblox Scripting Tutorial #18 - Tables
- local OmletteIngredients = {"Ham , Egg , Cheese"}
- print (Omlette Ingredient {1})-- will say ham
- print (Omlette Ingredient {2})-- will say egg
- print (Omlette Ingredient {3})-- will say cheese
- TABLE FUNCTIONS
- local OmletteIngredients = {"Ham , Egg , Cheese"}
- table.concat()-- merge them all together
- table.remove()-- will remove something from a table
- table.sort()-- will sort least to greatest only if your using numbers in a table
- table.remove,2)-- will remove egg
- table.sort(Name of number table)
- print(table.concat(OmeletteIngredients),""))
- Beginner's Roblox Scripting Tutorial #19 - in pairs loop / pairs loop
- Advanced Roblox Scripting Tutorial #1
- -- add a tool in Workspace then add a part then name it Handle
- -- put the tool in starter pack
- local Tool = script.Parent
- Tool.Activated:Connnect(function()
- local DestroyMe = game.Workspace.DestroyMe
- DestoryMe:Destroy()
- end)
- Advanced Roblox Scripting Tutorial #2 - Filtering Enabled
- nothing
- Advanced Roblox Scripting Tutorial #3 - Local Scripts
- -- only could be used in file based explorer items
- -- only the players could see that the server cant see it
- -- basically you assign it to the player only
- Advanced Roblox Scripting Tutorial #4 - Common Built-In Functions
- local Parts = game.Workspace.Parts:GetChildren()
- for i, v in pairs(Parts) do
- v:Destroy()
- wait(1)
- end
- --make a folder with 3 parts in it put in Workspace this will destroy th
- will get all children and create a table using the children
- ----------------------------------------------------------
- local character = game.Worksapce:WaitForChild("mariyandog999)
- will wait for mariyandog999 to join then will run the lines of codes
- you could write 2 parameter in the () Ex:("Part", True)
- ------------------------------------------------------------
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- -- you need to write that code for you do anything including the repStorage
- -- service is the major things with properties (like Chat, Workspace,Lighting, ServerS
- -- there is also small services like Gamepass service
- -- GetService() will see if its there if it is not there it will create it for you
- The PlayerAdded event fires when a player enters the game. This is used to fire an event when a player joins a game, such as loading the player’s saved GlobalDataStore data.
- -----------------------------------------------
- local Part = game.Workspace.Part
- Part:Clone()
- Part.Parent = workspace
- this will clone a part
- ---------------------------------------------------------
- Advanced Roblox Scripting Tutorial #5 - Mouse (Beginner to Pro 2019)
- you need to use a local script to get the mouse and in StarterPack
- local player = game.Players.LocalPlayer -- way to get your player find who he is
- local mouse = player:GetMouse()--
- mouse.Button1Down:Connect(function()
- print("player clicked mouse")
- end
- local player = game.Players.LocalPlayer -- way to get your player find who he is
- local mouse = player:GetMouse()--
- mouse.Move:Connect(function()
- print(mouse.Target)
- end)
- Advanced Roblox Scripting Tutorial #5.5 - Roblox Dev Forum & Wiki
- this just simply just a place for scripting and news for roblox
- Advanced Roblox Scripting Tutorial #6 - UserInputService (Beginner to Pro 2019)
- its like when a player presses a key
- Input is like if i press C or space that is input
- The primary purpose of this service is to allow for games to cooperate with multiple forms of available input - such as gamepads, touch screens, and keyboards. It allows a LocalScript to perform different actions depending on the device, and in turn, helps developers provide the best experience for the end user.
- The UserInputService is a service used to detect and capture the different types of input available on a user’s device.
- - create a local script then put it in starterplayerscripts
- https://developer.roblox.com/en-us/api-reference/class/UserInputService
- copy and paste that link to learn more about UserInputService
- UserInPutServoce = game:GetService("UserInPutService")
- UserInPutService.InputBegan:Connect(function(input,gameProccesedEvent)
- if input.KeyCode == Enum -- is like a list touchInput,KeyboardInput).KeyCode.A then --you could put any key in the spot i typed A
- print("Player pressed A")
- end
- end)
- -- enum is like a array of datas which you can choose from
- ------------------------------------------
- gameProcessedEvent is like if I make a giu and i click it the ourput will say true , but false if i am interacting with just the air
- ----------------
- if UserInputService.KeyBoardEnabled then
- print("you have a mouse connected")
- end
- if UserInputService.TouchEnabled then
- print("you have a touch screen connected")
- end
- if UserInputService.GamepadEnabled then
- print("you have a gamepad screen connected")
- if UserInputService.MouseEnabled then
- print("you have a mousescreen connected")
- Advanced Roblox Scripting Tutorial #7 - CFrame (Beginner to Pro 2019)
- -- Cframe is data you use to rotate positio 3rd objects
- -- stores position and orientation in 1
- local part = script.Parent
- print(part.Cframe)
- -------------
- local Part = script.Parent
- local NewCframe = Cframe.new(0,10,0)
- Part.Cframe = part.Cframe * NewCframe
- Advanced Roblox Scripting Tutorial #8 - Remote Events & Remote Functions
- use DeletePart-- name of remoteEvent:FireServer(Part--parameter you are using on) will fire the remote event
- -- they are used to let scripts on the server and local scripts on the client communicate
- SomeLocalScript ~~~~~~~ RemoteEvent ~~~~~~ SomeServerScript
- -- make a remote Event in RepStorage so clients and workspace can access it name it DeletePart and add a Part in the workspace
- -- IF YOU DONT USE REMOTE EVENTS LOCAL SCRIPTS WILL ONLY FIRE FOR 1 PLAYER
- -- remote events transfer data from local scripts to the RemoteEvent itself and finally will traverse the data to some a ServerScript
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local DeletePart = ReplicatedStorage:WaitForChild("DeletePart")-- this line of code will wait for the DeletePart
- local UIS = game:GetService("UserInputService")
- local Part = game.Workspace.Part
- UIS.InputBegan:Connect(function(input, gameProcessedEvent)
- if input.KeyCode == Enum.KeyCode.Delete then -- if players clicks the delete key on thier keyboard the print will fire
- print("Delete Key was pressed")
- DeletePart:FireServer(Part)
- end
- end)
- -- NOW I AM MAKING another script
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local DeletePart = ReplicatedStorage:WaitForChild("DeletePart")
- DeletePart.OnServerEvent:Connect(function(player, part)-- this line of code will see if the Delete:FireServer(Part) script ran if it ran this line of code will fire and go on.OnServerEvent is a normal event , but you need to put player as the first parameter and the second parameter will be the Part in the workspace cuz we are deleting that part.
- Part:Destroy()
- end)
- ------------------------------------------------------------
- Now Remote Functions
- DeletePartFunction-- name of remoteFunction:InvokedServer(Part)
- -----------------------------------------------------------
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local DeletePart = ReplicatedStorage:WaitForChild("DeletePart")
- local Part = game.Workspace.Part
- local UIS = game:GetService("UserInputService")
- UIS.InputBegan:Connect(function(input, gameProcessedEvent)
- if input.KeyCode == Enum.KeyCode.Delete then
- print("player pressed delete key")
- DeletePart:OnServerInvoked(Part)
- end
- end)
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local DeletePartFunction = game.ReplicatedStorage:WaitForChild("DeletePartFunction")
- DeletePart.OnServerInvoked = function(player, Part
- Part:Destroy()
- end)
- Advanced Roblox Scripting Tutorial #9 - Welding (Beginner to Pro 2019)
- -- welding is basically just making 2 parts move
- - if 1 part moves then part 2 will move
- [to weld go Model < View < then click create and then click weld
- local bluePart = script.Parent
- bluePart.Touched:Connect(function(hit)
- if hit.Parent:FindFirstChild("Humanoid") then
- local head = hit.Parent.Head
- bluePart.CFrame = head.CFrame * CFrame.new(0,10,0)
- local weld = Instance.new("Weld")
- weld.Part0 = head
- weld.Part1 = bluePart
- weld.C0 = head.CFrame:Inverse()
- weld.C1 = bluePart.CFrame:Inverse()
- weld.Parent = script.Parent
- end
- end)
- Advanced Roblox Scripting Tutorial #10 - TweenService / Tween (Beginner to Pro 2019)
- -- Tweening makes parts bigger and bigger as time goes on
- -- will change properties slowly of an object
- local TweenService = game:GetService("TweenService")
- local Part = script.Parent
- local Info = TweenInfo.new(
- 10, --Lenght(seconds)
- Enum.EasingStyle.Sine,
- Enum.EasingDirection.Out,
- 2,-- how much times you want it to do, --(reapet)
- false, -- Reverse(when ever you make it super big it will go back to normal
- 1 -- delay between each tween(seconds)
- )
- local Goals =
- {
- Size = Vector3.new(15,15,15);
- }
- local MakePartBiggerTween = TweenService:Create(Part,Info,Goals)
- MakePartBiggerTween:Play()-- Play is the built in function used to play the tween
- wait(10)
- [the parameters mean]
- - what you want to tween
- -how do you want to do or how will the tween act
- -What is the thing you want to achieve
- -- don't put a comma at the end
- {there is 3 EasingDirections}
- - In
- -Out
- -InOut
- {there is 8 EasingStyles}
- they determine how the tweening acts
- -Linear
- -Sine
- -Back
- -Quaf
- -Quart
- -Quint
- -Bounce
- -Elastic
- L
- E
- E
- T
- R
- D
- Advanced Roblox Scripting Tutorial #11 - Module Scripts & Dictionaries
- you could write code in a module and call it from another
- local Dictionary = {
- Cheese = "Cows",
- Bread = "Wheat"
- }
- print(Dictionary.Cheese)
- will print ("cow")
- -------------------------------------------
- insert module script in serverstorage
- local module = { -- the module table
- Dogs = "Cute, four-legged animals that love you"
- Cats = "Mean, four-legged animals that kill"
- }
- return module
- -- go to a script in workspace and type
- local AnimalTable = require(game.ServerStorage.ModuleScript)-- require means get the table
- print(AnimalTable.Dogs)
- -----------------------------------------------------------------------------------------
- Advanced Roblox Scripting Tutorial #12 - Lerp / Lerping
- You could move a part like 20% of the way
- local Part1 = game.Workspace.Part1
- local Part2 = game.Workspace.Part2
- for i = 0,1.01 do
- wait()
- Part1.CFrame = Part1.Cframe:Lerp(Part.Cframe, .5
- end
- Advanced Roblox Scripting Tutorial #13 - Data Store / Saving Player Data
- ---------------------------------------------------
- local DataStore = game:GetService("DataStoreService")
- local MyDataStore = DataStore:GetDataStore("MyDataStore")
- game.Players.PlayerAdded:Connect(function(player)
- local leaderstats = Instance.new("Folder")
- leaderstats.Name = "leaderstats"
- leaderstats.Parent = player
- local Cash = Instance.new("IntValue")
- Cash.Name = "Cash"
- Cash.Parent = leaderstats
- local PlayerId = "Player_"..player.UserId
- local data
- local success, errormessage = pcall(function()
- data = MyDataStore:GetAsync(PlayerId)-- your are storing the data in the player's user id
- end)-- GetAsync is a built in function that will load data and communicates with the data store which
- if success then
- Cash.Value = data
- end
- end)
- game.Players.PlayerRemoving:Connect(function(player)-- when a player gets removing the game will safe what he had in his leaderstats
- local PlayerId = "Player_"..player.UserId
- local data = player.leaderstats.Cash.Value -- will define data as what the player's leaderstats show
- local success, errormessage = pcall(function()
- MyDataStore:SetAsync(PlayerId, data)-- will Set the data that the player left with and permanent keep it on the player's Id
- end)
- if success then
- print("Everything went flawless")
- else
- print("The script completely failed")
- end
- end)
- Advanced Roblox Scripting Tutorial #14 - Animation
- insert a R15 block rig and then start animating
- when you make animation set the priority to Action
- file < export < create new < name it < copy the link < go to the page and copy the animation id
- -- you could only play animation in a local script
- make sure to put an animation in your local script
- -- paste your animation ID in your animation
- local BirdAnimation = script.BirdAnimation
- wait(10)
- local player = game.Players.LocalPlayer
- local char = player.Character
- local hum = char.Humanoid
- local BirdAnimation = hum:LoadAnimation(BirdAnimation)
- while true do
- wait(1.35)
- BirdAnimation:Play()
- end
- Advanced Roblox Scripting Tutorial #15 - Gamepasses | MarketplaceService
- copy the game pass id
- make a local script
- local MPS = game:GetService("MarketplaceService")
- local GamePassID = 17405519
- local function promptPurchase()
- local player = game.Players.LocalPlayer
- local hasPass = false
- local success, message = pcall(function()
- hasPass = MPS:UserOwnsGamePassAsync(player.UserId, GamePassID)-- Built in function will check if the player owns the gamepass which player and which gamepass
- print(hasPass)-- if the player owns then the print will work if not then the PromptGamePassPurchase will run
- end)
- if hasPass == true then
- print("Player has it")
- else
- MPS:PromptGamePassPurchase(player, GamePassID)-- PromptGamePassPurchase will prompt the gamepass to the player
- print(player.Name)
- print(GamePassID)
- end
- end
- promptPurchase()
- -- lines 11 through 14 will see if the player has the gamepass if they don't then the player will be prompted with the gamepas
- ----------------------------------------------------
- insert a server script
- local GamePassID = 17405519
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local Sword = ReplicatedStorage:WaitForChild("ClassicSword")
- local MPS = game:GetService("MarketplaceService")
- MPS.PromptGamePassPurchaseFinished:Connect(function(player, purchasePassID, PurchaseSuccess)-- the Event will fire if the player click buys or cancesl when the gamepass shows up
- if PurchaseSuccess == true and purchasePassID == GamePassID then-- if the player clicked buy then you will give the sword
- print("Purchased the Pass")
- Sword.Parent = player.Character
- end
- end)
- --{ parameters of the event }
- -- 1st parameter = The Player object for whom the prompt was shown
- -- 2nd parameter = The ID number of the game pass shown in the prompt (not to be confused with an asset ID)
- -- 3rd parameter = Whether the item was successfully purchased (false for errors and cancellations)
- -----------------------------------------------
- insert another script in script storage
- local GamePassID = 17405519
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local Sword = ReplicatedStorage:WaitForChild("ClassicSword")
- local MPS = game:GetService("MarketplaceService")
- game.Players.PlayerAdded:Connect(function(player)
- wait(1)
- local char = game.Workspace:FindFirstChild(player.Name)
- local hasPass = false
- local success, errormessage = pcall(function()
- hasPass = MPS:UserOwnsGamePassAsync(player.UserId, GamePassID)
- end)
- if success == true then
- print("player has the sword gamepass")
- Sword.Parent = char
- end
- end)
- Advanced Roblox Scripting Tutorial #16 - Developer Products
- -- same thing as gamepass just you could buy them mutliple times
- insert a local script
- local MPS = game:GetService("MarketplaceService")
- local Player = game:GetService("Players")
- local ProductID = 1169157152
- local player = game.Players.LocalPlayer
- MPS:PromptProductPurchase(player, ProductID)
- ----------------------------------------------------
- local MPS = game:GetService("MarketplaceService")
- local ProductID = 1169157152
- local players = game:GetService("Players")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local sword = game.ReplicatedStorage:WaitForChild("ClassicSword")
- local productID2 = 92341432
- local function processReceipt(receiptInfo)
- local player = players:GetPlayerByUserId(receiptInfo.PlayerId)
- if not player then
- -- 2312312
- return Enum.ProductPurchaseDecision.NotProcessedYet
- end
- if receiptInfo.ProductId == ProductID then
- if player then
- local char = game.Workspace:FindFirstChild(player.Name)
- local swordClone = sword:Clone()
- swordClone.Name = "Sword"
- swordClone.Parent = char
- end
- end
- return Enum.ProductPurchaseDecision.PurchaseGranted
- end
- MPS.ProcessReceipt = processReceipt
- -- something to know is that it takes time
- example: I was confused on gamepass/marketplaceserivce then i saw the 1 one of the comments it read
- " I thought it was hard at first but after 2 days i understood it and it was easy
- Advanced Roblox Scripting Tutorial #17 - Region3
- insert a script in ServerScriptSerivce
- local region = Region3.new(Vector3.new(0,0,0), Vector3.new(15,15,15))
- local part = Instance.new("Part")
- part.Anchored = true
- part.Size = region.Size
- part.Parent = game.Workspace
- while true do
- wait()
- local PartInRegion = workspace:FindPartsInRegion3(region, part, 1000)
- for i, part in pairs(PartInRegion) do
- if part.Parent:FindFirstChild("Humanoid") ~= nil then
- print("player found in region"..part.Parent.Name)
- local char = part.Parent
- char.Humanoid:TakeDamage(char.Humanoid.MaxHealth)
- end
- end
- end
- Advanced Roblox Scripting Tutorial #18 - Math Functions
- math.floor(6.14378932749732) -- will round it to 6 rounds it to the lower value like if instead of 6.1 i wrote 6.9 it will still round it to 6
- math.ceil(6.2321412412441) -- will round it to 7
- math.huge() -- will get the highest number
- math.rad()-- coverts degrees to radian used in Cframe
- math.pi()
- math.pow(5,2) -- exponents will do 5 times five
- math.abs(50) gives absolute value
- --------------------------------------------------
- Advanced Roblox Scripting Tutorial #19 - Sounds and Music
- insert a script in serverscriptstorage
- local Sound = game.Workspace.Sound
- Sound:Play()
- Sound:Pause()
- -------------------------------------------
- Advanced Roblox Scripting Tutorial #20 - Bindable Functions
- insert a bindable function in repStorage -- name it GetList
- insert a script in serverscriptservice
- local GetList = game.ReplicatedStorage:WaitForChild("GetList")
- local banList = {"UseCode_RainWay, UseCode_Tap"}
- GetList.OnInvoke = function(player)
- for i , v in pairs(banList) do
- if v == player.Name then
- print("player is in table")
- return true
- else
- print("player is not on the list")
- return false
- end
- end
- end
- --------------------
- insert another script in serverscriptservice
- local GetList = game.ReplicatedStorage:WaitForChild("GetList")
- game.Players.PlayerAdded:Connect(function(player)
- local IsPlayerBanned = GetList:Invoke(player)
- if IsPlayerBanned == true then
- player:Kick("You are banned")
- end
- Advanced Roblox Scripting Tutorial #21 - Pathfinding
- insert a character
- insert a script in the chracter
- local PFS = game:GetService("PathfindingService")
- local human = script.Parent:WaitForChild("Humanoid")
- local torso = script.Parent:WaitForChild("Torso")
- local path = PFS:CreatePath()
- path:ComputeAsync(torso.Position, game.Workspace.endingPart.Position) -- the 2 parameters are the starting a ending point where it shall start and finish
- local waypoints = path:GetWaypoints()-- creates waypoints that lead to the end
- for i, waypoints in pairs(waypoints) do
- local part = Instance.new("Part")
- part.Shape = "Ball"
- part.Material = "Neon"
- part.Size = Vector3.new(0.6, 0.6 , 0.6)
- part.Position = waypoints.Position + Vector3.new(0,2,0)
- part.Anchored = true
- part.CanCollide = true
- part.Parent = game.Workspace
- if waypoints.Action == Enum.PathWaypointAction.Jump then
- human:ChangeState(Enum.HumanoidStateType.Jumping)
- end
- human:MoveTo(waypoints.Position)-- if just do this then it will not work you need need to generate a path then make it move to the waypoint generated path
- human.MoveToFinished:Wait(2)
- end
- human:MoveTo(game.Workspace.endingPart.Position)
- if Enum.PathStatus.Success then
- print("The Robot Found it's way")
- else
- print("The Robot Did not find it's way")
- end
- Advanced Roblox Scripting Tutorial #22 - Magnitude (Distance)
- used to check the distance between things
- local Part2 = game.Workspace.Part2
- local mainPart = game.Workspace.mainPart
- local distance = (Part2.Position - mainPart.Position).magnitude
- print(distance)
- --------------------------------------------
- Advanced Roblox Scripting Tutorial #24 - Raycasting
- insert a part
- put a script in the part
- local part = script.Parent
- local FirstRay = Ray.new(part.Position, Vector3.new(0,50,0)) -- where you want it to start and end
- while wait(1) do
- local hit, position = game.Workspace:FindPartOnRayWithIgnoreList(FirstRay, {part})
- if hit then
- print("Part was hit")
- else
- print("no")
- end
- end
- --------------------------------------------------------------------------------------------
- local Rep = game:GetService("ReplicatedStorage")
- local Bullet = Rep:WaitForChild("Bullet")
- local turret = script.Parent
- local FireRate = 0.5
- local BulletDamage = 10
- local BulletSpeed = 150
- local AgroDist = 100
- while wait(FireRate) do
- local target = nil
- for i, v in pairs(game.Workspace:GetChildren()) do -- will loop through the workspace then find the NPC's hum and tor
- local human = v:FindFirstChild("Humanoid")
- local torso = v:FindFirstChild("Torso")
- if human and torso and human.Health > 0 then
- if (torso.Position - turret.Position).magnitude < AgroDist then -- if it is less then 100 then it will shoot
- target = torso
- print(target)
- end
- end
- end
- if target then
- local torso = target
- turret.CFrame = CFrame.new(turret.Position, torso.Position)
- local newBullet = Bullet:Clone()
- newBullet.Position = turret.Position
- newBullet.Parent = game.Workspace
- newBullet.Velocity = turret.CFrame.LookVector * BulletSpeed
- newBullet.Touched:Connect(function(objecthit)
- local human = objecthit.Parent:FindFirstChild("Humanoid")
- if human then
- human:TakeDamage(BulletDamage)
- end
- end)
- end
- end
- --------------------------------------------------------------------
- Advanced Roblox Scripting Tutorial #25 - Teleport Service
- local TP = game:GetService("TeleportService")
- local part = script.Parent
- part.Touched:Connect(function()
- local human = hit.Parent:FindFirstChild("Humanoid")
- if human then
- local char = hit.Parent
- local player = game.Players:GetPlayerFromCharacter(char)
- TP:Teleport(-- what ever the game ID is, player)
- end
- end)
- Advanced Roblox Scripting Tutorial #26 - ContextActionServic
- -A context is simply a condition during which a player may perform some action. like holding a tool
- - make a local script
- local CAS = game:GetService("ContextActionService")
- local part = game.Workspace.Part
- local function onButtonPress()
- part.BrickColor = BrickColor.new("New Yeller")
- end
- CAS:BindAction("turnBrickYellow",onButtonPress, true, "T")
- -- will show a button for mobile
- wait(5)
- CAS:UnbindAction("turnBrickYellow")
- ---------------------------------------
- Advanced Roblox Scripting Tutorial #27 - OrderedDataStores
- local DataStore = game:GetService("DataStoreService")
- local PlayerLevels = DataStore:GetOrderedDataStore("PlayerLevels")
- local scores = {
- ["MarkGamerZobieHunter312414"] = 154,
- ["SallyWacky"] = 255,
- ["NancyPlays"] = 7,
- ["UseCodeTap"] = 57,
- ["Sus"] = 412
- }
- for player, level in pairs(scores) do
- PlayerLevels:SetAsync(player, level)
- end
- local pages = PlayerLevels:GetSortedAsync(false, 3)
- print(pages)
- while wait do
- local data = pages:GetCurrentPage()
- print(data)
- for i, v in pairs(data) do
- print(v.key)
- end
- if pages.IsFinished then
- break
- else
- print("Next")
- pages:AdvanceToNextPageAsync()
- end
- end
- -------------------------------------------------------
- Advanced Roblox Scripting Tutorial #28 - Camera Manipulation
- wait(5)
- local Cam = workspace.CurrentCamera
- local player = game.Players.LocalPlayer
- local FocusPart = game.Workspace.FocusPart
- Cam.CameraType = "Fixed"
- Cam.Focus = FocusPart.CFrame
- wait(3)
- Cam.CameraType = "Custom"
- Cam.CameraSubject = player.Character.Humanoid
- ----------------------------------------------
- Advanced Roblox Scripting Tutorial #29 - RunService
- local RunService = game:GetService("RunService")
- RunService.HeartBeat:Connect(function()
- print("Hi")
- end
- Advanced Roblox Scripting Tutorial #34 - MessagingService
- -- global server communication at the same time
- insert 2 server scripts
- local Message = game:GetService("MessagingService")
- Message:SubscribeAsync("PlayerFoundItemAnnouncement", function(message) -- subscribe to a topic the 1st parameter is the Topic, the 2nd paramter is a function the data is being sent the function so you could put a paramter in the function to use the data later on
- print(message.Data)
- print(message.Sent)
- end)
- wait(5)
- Message:PublishAsync("PlayerFoundItemAnnouncement","Hello gamers")
Advertisement
Add Comment
Please, Sign In to add comment