#need some help with my code

1 messages · Page 1 of 1 (latest)

ornate river
#

trying to make the parts (literally called "part") rotate in sync around the "centre part without it disrupting their individual rotation around the centre. Basically making a separate rotation for the part as a whole on top of the parts individual rotation.

open vault
ornate river
#

the central part?

open vault
ornate river
#

the code creates seperate parts and has them orbit around a centre, they arent under one part

open vault
#

why not just set everyones pivot the the center OR make a model and set this pivot to center

ornate river
#

if i set all the parts pivot to the centre, the radius no longer becomes dynamic but ill try the model one

open vault
#

It would look something like this

#

Make sure the center part is the PrimaryPart of the model

ornate river
#

when i try to rotate the parts they are put back into their original position because of how their rotation is calculated

open vault
#

yo

#

Lets forget math and scripting

#

What do you want to achieve

ornate river
#

basically a second rotation

#

a global and independant rotation for the parts

open vault
#

Why is the Model one not working

ornate river
#

when you rotate the parts in the model, it moves them but the calculation for rotation wouldnt change so it just puts them back to where they would be

open vault
#

what the hell are you calculating

ornate river
#

local phase = math.random() * 2 * math.pi
-- Animation variables
local angle = 0 -- Current angle in radians
local Time = 0
-- Start animation loop using Heartbeat
local function Destroy()
while part.Transparency < 1 do
part.Transparency += 0.01
task.wait(0.001)
end
part:Destroy()
end

        task.spawn(function()
            while part and part.Parent do
                local dt = RunService.Heartbeat:Wait()
                
                -- Update angle (convert degrees/sec to radians/sec)
                angle += math.rad(rotationSpeed) * dt
                

                
                Time += dt
                -- Calculate new position
                local x = math.cos(angle) * radius
                local z = math.sin(angle) * radius
                local y = origin.Y + math.sin(tick() * bobFrequency + phase) * bobAmplitude + (Time*60)
                
            
                
                
                radius = (math.sin(Time * 0.25 * math.pi * 2 ) * 7) + 7 -- Distance from the center
                
                -- Apply position
                part.Position = Vector3.new(origin.X + x, y, origin.Z + z)
            end
        end)
        
        
        local targetSize = Vector3.new(73.489, 17.936, 73.489) * 1.25
        local SizeTweenInfo = TweenInfo.new(1.25,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut)
        local sizeTween = TweenService:Create(part,SizeTweenInfo,{Size = targetSize})
        sizeTween:Play()
#

it basically is tracking the co-ordinates around a circle using radians to find where it would be

open vault
#

🥀🥀🥀🥀

ornate river
#

am i cooked?

open vault
#

aint no way anyone able to read that

#

kinda

#

no ones gonna look through that script cause its so ahh to read

#

but we can find a diffrent solution which is also more readable and maybe easier for you

#

I just dont understand what you are trying to do

ornate river
#

i was thinking that if i can change the starting orientation, that it would have the same effect

hot ospreyBOT
#

studio** You are now Level 2! **studio

ornate river
#

since its all rotating at the same rate rn, if i change the point at which it starts to go out, then it might work

open vault
#

this is how I understood it you want 2 rotation thingies

ornate river
#

sort of ye

open vault
#

but a model would legit do that or not

ornate river
#

na

open vault
#

I dont get it

#

I would do this with PivotOffset tho

#

and not with tweening

ornate river
#

the tweening is only for the size

open vault
#

or like tween but

#

bro

#

I dont even understand where you would use that

#

like watafak

#

are you even doing

ornate river
#

basically a tornado

open vault
#

USE A FUCKING MODEL AND ROTATE THE PRIMARY PARTTTTTTT

#

why wouldnt that workcrying crying crying crying

ornate river
#

i cant adjust the radius if i use a model

open vault
#

then use pivot there you can

#

This is the simpliest way of fixing ur problem

ornate river
#

hang on im onto something

open vault
open vault
ornate river
#

omg it worked lol

#

thats so dumb

#

local x = math.cos(angle+xOffset) * radius
xOffset += 0.05

#

that was literally all i had to do

open vault
#

fuck math

#

dont send me that

ornate river
#

ikr

open vault
#

I dont want anything todo with that

ornate river
#

dude i spent 2 hours learning radians to jsut add an offset

#

im so done

open vault
#

I learnt 3h yesterday about Type Checkerevilcat

ornate river
#

the hell is a typechecker

open vault
#
--!strict

--[[
======================
==== END USER API ====
======================

Credits: zyos73

]]--



export type API = {
    DEBUG: boolean,
    _VERSION: string
}

local _API : API = {
    DEBUG = false,
    _VERSION = "0.1"
}




local API = setmetatable({}, {
    __index = _API,
    __newindex = function(_, input, newvalue)
        
        if input:match("^_") then
            error(`\n{input} is read-only`)
            return 
        end
        
        if typeof(rawget((_API :: any), input)) ~= typeof(newvalue) then 
            error(`\n{input} assigned wrong type: \nexpected: {typeof(rawget((_API :: any), input))}, \ngot: {typeof(newvalue)}`)
            return 
        end

        (_API :: any)[input] = newvalue
    end
})

return API
#

just to create this

ornate river
#

mate im lost on the first line

open vault
#

--!strict activates the like strict mode for type checker

ornate river
#

is this just to check for like data type values

open vault
#

_API has the type API and DEBUG is supposed to be a boolean so it underlines it orange cause its a number that there is something wrong yk

ornate river
#

oh i get it

#

so it just stops people putting the wrong type of data like a integer for a boolean value

open vault
#

basicly

#

also if you use auto completion from a custom module itll show you what type it needs

ornate river
#

might learn that if i have the time

open vault
#

ye its pretty intresting

#

but not really needed if you have basic stuff

#

if you dont use --!strict its just not gonna show you that its the wrong type

ornate river
#

i hate it when code does stuff like that

#

cant it just realise that i want it to show me

open vault
#

Lua has no constants thats why this exists probably

local number : number = 3

number = "x"
#

its not wrong but if you expect the number to be a number and like make math with it even tho its a string its gonna crash and thats like the main reason to learn it

#

heres an example of the auto complete btw

ornate river
#

ive done python and is it not the same in lua where you can just go int(variable) and make sure its an integer

open vault
#

you can do tonumber()

#

but maybe thats just luau idk

ornate river
#

if that works then why cant you just do that instead of learning the type check

hot ospreyBOT
#

studio** You are now Level 3! **studio

ornate river
#

this bot i swear

open vault
#

that was an example if you expect a ValueBase and you want to change the Value but its not a ValueBase thats gonna also crash

#
local Bool : ValueBase = 3
Bool.Value = true --error
#

the strict type checker is gonna tell you "yo thats the wrong type here"

ornate river
#

so it will just do a warning and then move on instead of an outright crash

ornate river
#

so it will still crash

open vault
#

orange thingy

ornate river
#

oh

open vault
#

yes it will crash

ornate river
#

so you dont even have to run it

open vault
#

yes

ornate river
#

and itll detect

open vault
#

ye

ornate river
#

ok thats cool

open vault
#

if you want a value to be a changeable type you can give it local newVar : any = 3

ornate river
#

so then you can make that into a string later

open vault
#

yes

#

but that breaks the use of strict

ornate river
#

where could you use this

open vault
#
local API = setmetatable({}, {
    __index = _API,
    __newindex = function(_, input, newvalue)
        
        if input:match("^_") then
            error(`\n{input} is read-only`)
            return 
        end
        
        if typeof(rawget((_API :: any), input)) ~= typeof(newvalue) then 
            error(`\n{input} assigned wrong type: \nexpected: {typeof(rawget((_API :: any), input))}, \ngot: {typeof(newvalue)}`)
            return 
        end

        (_API :: any)[input] = newvalue
    end
})

return API
#

Here

#

I know 100% that _API is the right type thats why im forcing it to be any

ornate river
#

but like what is its use in like a game scipt

#

where can you apply it

open vault
#

wdym

ornate river
#

if i wanted to use a Instance thats to like make a new part so i can spawn new things into the game. so i can use that to make new things. what exactly can you do with checking the data type of something.

#

surely you should already know what type it is

#

or am i just being thick

open vault
#


local function resizePart(part : BasePart) --makes sure its a BasePart
    part.Size = Vector3.new(5,5,5)
end

resizePart(game.Workspace.Part)
#

do you mean something like this

ornate river
#

ye

#

surely you already know what you are putting into it

open vault
#

o wait

#

you wanted to know wehn to use any

ornate river
#

no i mean when to you the checking this as a whole

#

like why would i need to check it if i know what im putting in

open vault
#

Lets say you have 1000 lines of code and you want to call a function but you forgot if it needs a string or a number with type checker youll instantly know what you need cause it gets orange

ornate river
#

so it basically is a quick way to check variable types

open vault
#

yes

#

it doesnt really have a use case in the game mechanics but for yourself

ornate river
#

thats pretty cool

#

i wont use it because my code rn is like 200 lines max

#

but it sounds helpful

open vault
#

ye

#

I also just started using it after like 5 years with luau

ornate river
#

i got like 4 months on it and i look at the pro scripting channel and it looks like ancient aztec

#

i swear i saw someone summoning a demon in that code

#

anyway thanks for the help

#

and telling me about the type check

open vault