#Scripting problem

1 messages · Page 1 of 1 (latest)

hollow crow
#

I got a problem in my script. I'm new so some advice would be appreciated. I'm tryna script a character touching a door and that door would open in a 90 degree angle. I thought of touch part = cframe.angle. This ius what i did for the handle of the part and I set up the door and the handle of the door into one folder. I also wanted to try to make both the handle and the door move at the same location

local ClickDetector = script.Parent
ClickDetector.Touched:Connect(function(ClickDetector)
if ClickDetector.Touched then
ClickDetector = CFrame.Angles(0, math.rad(90), 0)
end
end)

static charm
#

Print(“hi”)

hollow crow
#

ok

#

yea it works

#

but the cframe isnt rotating

#

also i'm having trouble tryna move both the handle and the door

austere shuttle
#

What CFrame.Angles() does is it creates a new instance of A CFrame, with only rotational components, (0,0,0) in the positional one (moving it to the origin). You would want to get the CFrame of the Door, and apply

hollow crow
#

so i would need to move the door into the origin>

#

?

austere shuttle
#

This is a script that I already made that rotates a cube, it doesn't exactly apply, but it should help a bit
local cube = script.Parent.WireframeCube
cube.PrimaryPart = cube:FindFirstChild("Cube.001")
local cf = cube:GetPrimaryPartCFrame()
local rotation = CFrame.Angles(0, math.pi/4, 0)
while true do
cf *= rotation
cube:SetPrimaryPartCFrame(cf)
task.wait(0.5)
print("Hello!")
end

static charm
#

local function hi()
Print(“dude”)
End

It will work

austere shuttle
#

It selects a part in the cube to act as the "PrimaryPart" (the one we look at to get the CFrame). It then creates a rotational CFrame, which it then repeatedly applies the rotation to the primary part's CFrame (cf *= rotation) and then sets the CFrame of the cube to the new CFrame (cube:SetPrimaryPartCFrame(cf)

#

Beginning the linear algebra series with the basics.
Help fund future projects: https://www.patreon.com/3blue1brown

Music: https://vincerubinetti.bandcamp.com/track/grants-etude

Thanks to Elo Marie Viennot and Ambros Gleixner from HTW Berlin (www.htw-berlin.de) for contributing German translations and dubbing.

Thanks also to these viewers for...

▶ Play video
rustic wedge
#

Bro wtf are these scrips

hollow crow
#

alr thanks

lyric aspenBOT
#

studio** You are now Level 1! **studio

hollow crow
#

much appreciated

rustic wedge
#

Btw a clickdetector isnt a basepart so it cant be touched. Tou would have to use mouseclick instead

static charm
rustic wedge
#

You also cant set the cframe of a click detrctor

hollow crow
#

at first I tried to make it so that a mouse button click on the object would make it rotate but it was way too complex for me so i decided to just run touch

oak ridge
#

and change the c0 to open/close it

rustic wedge
#

Local CD = script.Parent
Local door = ur door instance here

CD.MouseClick:Connect(function()

    Door.CFrame = Door.CFrame * CFrame.Angles(0, math.rad(90), 0)

end)

#

I’m typing on phone so it hard

oak ridge
#

and this assumes the door is a basepart

rustic wedge
#

Ik

#

U would have to mane a hinge

static charm
#

no no guys

rustic wedge
#

And weld the door to the hinge

#

And weld the doorknob to the door

hollow crow
rustic wedge
#

And make sure the hunge is anchored and the door isnt and the door handle isnt

static charm
#

Game.workspace.Part:waitforchild(“part”

#

This will work

rustic wedge
#

Bruh

hollow crow
#

alr so I welded them together

#

do i add a script on the weld restraint?

rustic wedge
#

That dosent rly matter

#

As long as ur instancing correctly

hollow crow
#

wym instancing correctly?

rustic wedge
#

Like door beeing script.parent for example

#

If the script isn’t in the door then that wouldnt work

hollow crow
#

alr

#

local CD = script.Parent
local door = script.Parent

CD.MouseClick:Connect(function()

door.CFrame = door.CFrame * CFrame.Angles(0, math.rad(90), 0)

end)

#

do I have to reference click detector as a handle with the door

#

this script is the door rn

rustic wedge
#

Well the door is the same instance as the click detector now

hollow crow
#

o

#

So i need to make seperate instances?

lyric aspenBOT
#

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

rustic wedge
#

Wait can you send a screenshot of the workspace?

hollow crow
#

yea

rustic wedge
#

You dont have a clickdetector added

hollow crow
#

the script I did before?

rustic wedge
#

Make a clickdetector inside of the union

hollow crow
#

k

rustic wedge
#

Just change CD to script.Parent.ClickDetector

#

It should work

fierce marsh
#

why changing cframe of the click detector

#

is that what is intended

hollow crow
#

wait im confuzzled

fierce marsh
#

do clickdetectors even have cframe

hollow crow
#

local CD = script.Parent
local door = script.
CD.MouseClick:Connect(function()

door.CFrame = door.CFrame * CFrame.Angles(0, math.rad(90), 0)

end)

fierce marsh
#

yes

#

but reference them both correctly

hollow crow
#

im not sure what to put for local door = script.

fierce marsh
#

well click detector isn’t even the parent

rustic wedge
#

Script.Parent

rustic wedge
hollow crow
#

so I just change CD into script.Parent.ClickDetector?

rustic wedge
#

And make sure door is script.Parent

fierce marsh
#

do you understand why?

#

the parent of your script is not the click detector, the parent is basically the instance that your script is in

#

it is inside of the union

hollow crow
#

so the union is the parent>

#

?

fierce marsh
#

of the script he’s

#

yes

#

but then u can reference any children of the union

#

like script.parent.clickdetector

#

which essentially is the same as doing game.workspace.union.clickdetector if u understand what that does

hollow crow
#

and the parent is the location of where the script is in

fierce marsh
#

yes

hollow crow
#

alr thanks

#

local script.Parent.ClickDetector = script.Parent
local door = script.Parent
script.parent.ClickDetector.MouseClick:Connect(function()

door.CFrame = door.CFrame * CFrame.Angles(0, math.rad(90), 0)

end)

#

so do i do smthn like this then?

fierce marsh
#

try it

hollow crow
fierce marsh
#

wait

#

no

#

literally just do

#

local ClickDetector = script.Parent.ClickDetector

#

u over complicated it

hollow crow
#

oh alr

fierce marsh
#

Clickdetector is just a variable

#

ur assigning the actual clickdetector instance to the variable Called clickdetector

hollow crow
#

oh okay

#

the variable = script references clickdetector

#

ey it works

#

kinda

#

preciate the help

rustic wedge
fierce marsh
#

u need to do it around the hinge

lyric aspenBOT
#

studio** You are now Level 11! **studio

hollow crow
#

ye im down

fierce marsh
#

and add a weld restraint

#

kinda complicated for beginner so yeah hopefully he can explain

hollow crow
#

alr thanks

hollow crow