Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

why doesn't this script work?

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

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.