Hello, Scripting Helpers.
I am working on an SCP Project, and I'm currently trying to add a new item into the SCP-914 script. Basically what I'm trying to do is turn the item "Water Tank" into a "Hydrogen Tank," and clone the newly converted Hydrogen Tank. The first Hydrogen Tank gets converted without issue, but the second Hydrogen Tank gets completely broken. Is there any fix to this? Am I positioning it wrong? Any help would be greatly appreciated.
Code:
elseif item.Name == "Water Tank" then item.Handle.BrickColor = BrickColor.new("Pastel green") item.P1.BrickColor = BrickColor.new("Dark green") item.P2.BrickColor = BrickColor.new("Dark green") item.P3.BrickColor = BrickColor.new("Dark green") item.P4.BrickColor = BrickColor.new("Dark green") item.Name = "Hydrogen Tank" item.Handle.Position = Vector3.new(-144, 85.5, 795) local newitem = item:Clone() newitem.Parent = game.Workspace script.Disabled = true
Note: The tool is comprised of multiple parts.
The second Hydrogen Tank should spawn like this
But the second Hydrogen Tank spawns like this
I tried revising the code using an answer that SerpentineKing gave me, however, this happened.
SerpentineKing's code:
elseif item.Name == "Water Tank" then item.Handle.BrickColor = BrickColor.new("Pastel green") item.P1.BrickColor = BrickColor.new("Dark green") item.P2.BrickColor = BrickColor.new("Dark green") item.P3.BrickColor = BrickColor.new("Dark green") item.P4.BrickColor = BrickColor.new("Dark green") item.Name = "Hydrogen Tank" item.Handle.Weld.C0 = CFrame.new(-144, 85.5, 795) local newitem = item:Clone() newitem.Parent = game.Workspace script.Disabled = true
As awesomeipod is saying the only issue with the part of the script shown is that you changed the position of the handle, breaking the welds, which you don't want to do.
item.Handle.Position = Vector3.new(-144, 85.5, 795)
In order to get around this, Welds have a Property named C0
which determines the offset from the other welded part
Assuming you want the clone to also be welded, after creating the clone, you can use this iteration
newitem.Handle.Weld.C0 = CFrame.new(0, 0, 0)
If not, just replace the first line written above with
item.Handle.Weld.C0 = CFrame.new(0, 0, 0)
while changing the CFrame.new values
Hello! I believe that it is not the issue with your code and it is with the tool itself. You have to change the server scripts inside of the tool to local scripts, or else it will not show up on the client.