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

why doesn't this script work?

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
x = script.Parent.Union.Position
function gsdfgs(x)
    script.Parent.Union.BodyPosition.position = Vector3.new(300, 44.5, 62.1)
    wait(35)
    if script.Parent.Union.Position == Vector3.new(198.61, 44.181, 62.1) then
        script.Parent.Union.BodyPosition.position = x
        script.Parent.Union.Position = Vector3.new(49, 44.5, 62.1)
    end
end

game.Workspace.Button.ClickDetector.MouseClick:connect(function()
    gsdfgs()
end)

I want it to go to the position and come back in 35 seconds but it isn't working for some reason. I'm not sure why it's not working and I would appreciate it if you could tell me what I might be doing wrong. it moves well but it never comes back.

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

Why would the object be at 198.61 for x after 35 seconds of being told to target 300?


That said, it doesn't really make sense to check precisely where it is (e.g., using ==) because it won't be exactlyin the right place (it will be at the least thousandths of a stud off).

The check is probably superfluous.

You don't given an x when you call the function, either.

Consider doing something like this:

local obj = script.Parent.Union

function target(position)
    obj.BodyPosition.position = position
end

function clickEvent()
    local positionOne = Vector3.new(300, 44.5, 62.1)
    local positionTwo = Vector3.new(49, 44.5, 62.1)
    ---
    target(positionOne)
    wait(35)
    target(positionTwo)
end

game.Workspace.Button.ClickDetector.MouseClick:connect(clickEvent)
Ad

Answer this question