Reverse Ability Trouble

Hello! I am DizzyTwisted, i have a HUGE project Demo im working on and im having a problem with the main mechanic.

Its a reverse ability. where objects that are destroyed will be put back together at the press of a button.

For instance a chair, the chair is unanchored and the parts are not together, the player would click on a part of the chair, and it would be highlighted (because it has a value that allows it to be reversed) and if they hold E or something, the parts would move to form a chair (Anchored). if they release E the parts will fall back down (Un-anchored.)

now a chair is just an example, the objects would range from a bridge made of rocks to a key broken into pieces.

But as of today. i have been up all night trying to find a solution and i haven’t been able to alone, i’ve tried A.I. but its of no help. So, im coming to the community for help. Let me show you what i have and hopefully someone could help me.

This is a Function module with my camera script and a script that i tried to make that was supposed to gather all of the things in workspace with a “Reversable” Tag and check if its in a group, if it is, then create a dictionary in which it has the name and position of all of the items with the “Reversable” Tag, and then maybe in the future i can call back on it, and get the original position of it and tween it back? but it didn’t work as you can maybe tell.

Next is the script connecting to that, which is a script in StarterPlayerScripts, and its a lot.

This part isn’t a problem, essentially what this is doing is checking what the mouse clicked on, seeing if it has the tag “Selected” and if it does, and its not already selected then it’ll highlight it and put its name in a table, but the player can only select 2 objects at once, if they try to select more it won’t work. They can deselect it by simply rightclicking and the highlight will go away, and remove it from the table.

The second part of the script is the problem.

I was trying to make it so that the original position of the part will be inside of a string value inside of the part and i can just call it whenever i needed to tween it back to normal, however, it didn’t work. so now im at a loss.

What i am asking for is not entire scripts from you guys, but nudges in the right direction, and by nudges i mean actual tips not riddles hidden in hieroglyphs.

I have tried to hire people but they never answered, so ill pay anybody all that i have right now (Which is $10) if they can make this system for me, if you desire more, i am able to get more but it will take time but as of now, its all i have : / .

Thank you for reading, Have a nice day!

You should use Vector3Value instead.

I dont think i put this in there, but when i held it, it kept printing “Searching” and never went past that print line. so i dont know.

May you provide the full screenshot of your Mouse.Button1Down event? This seems to be the only way a model’s Selected attribute can change to a true state

This is the full code

local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
local SelNumber = 0
local Notice = script.Selection_Notice
local NoticeCopy = Notice:Clone()
local Selected = {}
local CollectionService = game:GetService("CollectionService")
local UIS = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local TI = TweenInfo.new(3,Enum.EasingStyle.Linear,Enum.EasingDirection.In,0,false,0)

local function Check()
	for index, descendant in pairs(Selected) do
		if table.find(Selected,Mouse.Target.Name) then
			local Findindex = table.find(Selected,Mouse.Target.Name)
			
			Notice.Adornee = nil
			table.remove(Selected,Findindex)
			SelNumber = SelNumber - 1
			Mouse.Target:SetAttribute("Selected", false)

			print(Selected)
			print(SelNumber)
		end
	end 
end
Mouse.Button1Down:Connect(function()
	if not Mouse.Target then return end
	
	if SelNumber >= 2 then return end
	
	if Mouse.Target:GetAttribute("Selected") ~= false then return end
	
	if CollectionService:HasTag(Mouse.Target, "Reversable") and Mouse.Target:GetAttribute("Selected") == false then
		Notice.Adornee = Mouse.Target
		SelNumber = SelNumber + 1
		Mouse.Target:SetAttribute("Selected", true)
		table.insert(Selected, Mouse.Target.Name)
		print(SelNumber)
		print(Selected)
		return
	end
	if Mouse.Target:GetAttribute("Selected") == true then return end
end)
Mouse.Button2Down:Connect(function()
	Check()
end)


UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Q then
		for _, v in ipairs(game.workspace:GetDescendants()) do
			print("Searching")
			if v:HasTag("Reverseable") and v:GetAttribute("Selected") == true then
				print("E1")
				local OriginPos = v.OriginPos.Value
				local OrginOrient = v.OriginPos.OriginOrient.Value
				print("Made")
				TweenService:Create(v, TI, {Position = OriginPos}):Play()
				print("playing")
				if v.Position == OriginPos then
					v.Anchored = true
				end
			end
		end
	end
end)

UIS.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Q then
		for _, v in ipairs(game.workspace:GetChildren()) do
			if v:HasTag("Reverseable") and v:GetAttribute("Selected") == true then
					v.Anchored = false
			end
		end
	end
end)

Oh I get it now, you have a grammar mistake for checking if the object has a tag in Mouse.Button1Down. You’re checking for “Reversable”, instead of “Reverseable”

1 Like

Oh! That was the problem! Thank you! However… that raises more problems, when i hold down Q it lags my laptop REALLY bad. Not only that it doesn’t move to the right position, AND it doesn’t tween as smoothly as i would have hoped.

1 Like
  1. When you’re holding down Q, in your InputBegan event you’re getting Descendants of workspace, not Children as you did in InputEnded event, alongside anchoring and unanchoring a lot of parts, so it makes sense.

  2. I assume the wrong positioning has to do with you never actually anchoring the parts in InputBegan event, since your check for Position (if v.Position == OriginPos then) will never match due to your slow Tween. Just change it to the Anchored state right away

  3. Your tween isn’t smooth because you’re using linear interpolation, not others like Sine or Quad

EDIT: for the 2nd one, instead of storing a Position, store a CFrame value as it has both Rotation and Position

I do not have the knowledge to do that. also, the script breakes when i use :GetChildren() instead of :GetDescendants() so im at a stale mate here…

image

Not sure how tedious that’d be, but you can replace each part with the CFrameValue instead of Position. For my own personal approach, instead of storing a value inside each part, i’d just do this:

local TweenService = game:GetService("TweenService")
local TI = TweenInfo.new(3, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0)
local OriginalCFrames = {}

for _,v in workspace:GetChildren() do
	if not v:IsA("BasePart") then continue end
	OriginalCFrames[v] = v.CFrame
end

--when i need to move everything back to its normal state
for part, origin in OriginalCFrames do
	part.Anchored = true
	TweenService:Create(part, TI, {CFrame = origin}):Play()
end

This probably has to do with you using game.workspace instead of a global workspace, a default Workspace service starts with a capital letter.

The Problem with this is, i can only call one part. i believe i didn’t specify how many parts. Like a chair, i wanted to be able to click on a part and it gather all the parts and when i press E it’ll move. and the script that im showing you right now is just a test script, the final script would look different.

This worked, however, this arises a whole different problem. im gonna post it on another post though. Thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.