You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want to make an AI system kinda like FNAF where the animatronics have an int value inside of them named “levels” and the higher the level the quicker they teleport around.
What is the issue? Include screenshots / videos if possible!
I am not sure where to start.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried YT and DevForum
I have actually tried to make a FNAF styled game on roblox, except the didn’t teleport throughtout cameras they walked.
local character=script.Parent
local level=workspace.Modifiers[character.Name].Value --The character's agression level
local bootTimer=math.clamp(math.random(5,15)*(20-level),5,10)
while true do --This loop to wait before moving at the start
if bootTimer>0 then
bootTimer-=1
else break end
task.wait(1)
end
You could adapt this bit of code as a baseline for your way, the map is by no means perfect as it is not refined (because i never balanced it) but it will work as a base
As for teleportingthe animatronics, you can use model:PivotTo() or model.PrimaryPart.CFrame and set the goal to a pre placed position in your map
I’ll explain the code @uriel_Gamer444 provided as an example.
We’ll go step by step.
Variables
I’m pretty sure you’ll understand this.
local character = script.Parent
local level = workspace.Modifiers[character.Name].Value
Boot timer
Here, we have declared a variable called bootTimer. This variable has been assigned the value of math.clamp(math.random(5,15) * (20 - level), 5, 10).
It looks scary to a beginner, let’s break it down.
math.clamp(x, min, max)
math.clamp is a function provided by roblox’s math module.
You can think of it as something that restricts the x variable to fit within the bounds of min and max.
If x goes below min, then x = min, If x goes above max then x = max.
math.random(5, 15) * (20 - level)
math.random() generates a number within the given range.
The number then gets multiplied by (20 - level), where level = aggression of the character
Then the final value gets clamped within (5, 10).
while loop
In this loop, we check if bootTimer > 0, if it is, then we decrease bootTimer by 1 per second. Otherwise, we break out of the loop. This serves as a starting timer for the animatronics. Hence if they are more aggressive, the timer becomes less in value.
Ok thanks this helped me understand it a bit more, but what i still don’t understand is why you check if bootclamp > 0. Like what is that about. And what are the numbers 5,10 there for? And why do we times the thing by 20?
These are values you can change for your liking. @uriel_Gamer444 has adjusted these for himself.
The reason why we check if bootTimer is above 0 is that we have to reduce it every second. If bootTimer is less than 0, we need to break out of the loop.
let’s say math.random(5, 15) returned something like 7. Then we multiply 7 with (20 - level). let’s say the level is 10, then it’s 7 * (20 - 10) which is 70.
Then we clamp 70 to fit within 5 and 10. Let’s say 10.
Then the bootTimer will last for 10 seconds.
brother you may want to do some tutorials on basic levels of scripting before heading straight into this… especially since Roblox is your first scripting experience. (if you need to ask questions like this constantly it’s going to be a long and painful rodeo for you!)