Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

value isnt detecting and CFrame is confusing help?

Asked by 4 years ago
Edited 4 years ago

im not sure what im doing i suck at scripting

i have been working on this for hours and i think im going crazy

its a down only door, example:(when Close.Value = 1 then Door goes down to close hallway)

and the script wont detect the value

thanks

also heres the script

local sp = script.Parent
local door = sp.door


if workspace.GameData.Close.Value == 1 then
    for i=1,door.Size.x/.2*3+1 do 
        door.CFrame = door.CFrame*CFrame.new(0,-.2*.2,0)
        door.Close:Play()

    end
end

1 answer

Log in to vote
0
Answered by
Benbebop 1049 Moderation Voter
4 years ago
Edited 4 years ago

As for the the script not detecting when the value reaches one. The problem is that the way scripts work, they execute their code once and never again (Unless you are using ModuleScripts). But people get around this by using loops and functions. For you the best way to do this would be a function, specifically the changed function.

workspace.GameData.Close.Changed:Connect(function()

Changed means when anything about the Value changes it will execute this code. Connect just means when this event happens the code will run. Make sure when closing this piece of code you add a bracket behind the end. Put into your code it would look like this:

local sp = script.Parent
local door = sp.door

workspace.GameData.Close.Changed:Connect(function()
    if workspace.GameData.Close.Value == 1 then
        for i=1,door.Size.x/1.6 do 
            door.CFrame = door.CFrame*CFrame.new(0,-.04,0)
            door.Close:Play()

        end
    end
end)

As for the CFrame. CFrame is not a parameter of a BasePart it is instead a type of value that stores 3D coordinates. Meaning that CFrame is used for size, position, etc. So what you want to do is put a CFrame into the position parameter of the BasePart. Like so:

door.position = CFrame.new(0, door.Position.Y * -.04, 0)

I collapsed all the needles equations in the script you had

You will want to keep everything inside the brackets of the CFrame.new. Also not sure why you have door.close:Play() written there, where you trying to do a tween? This all added to your code would be:

local sp = script.Parent
local door = sp.door

workspace.GameData.Close.Changed:Connect(function()
    if workspace.GameData.Close.Value == 1 then
        for i=1,door.Size.x/1.6 do 
            door.position = CFrame.new(0, door.Position.Y * -.04, 0)
        end
    end
end)
Ad

Answer this question