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

Tool not spawning correctly when cloned. How do I fix?

Asked by
Ma02rc 4
5 years ago
Edited 5 years ago

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
0
Local script or server script? CaptainD_veloper 290 — 5y
0
Server script. Ma02rc 4 — 5y
0
its because you change the handle's position, causing the welds associated with the handle to break awesomeipod 607 — 5y
0
Well, is there anyway to move the entire tool over to the position where I want it to be, without breaking the welds? Ma02rc 4 — 5y
View all comments (3 more)
0
The Weld C0 Property is not the position in the global field, but is instead the offset from the other part determined by the weld, so weld.C0 = CFrame.new(0, 0, 5) would be 5 studs away (z-axis) from the Weld's Part1 Instance SerpentineKing 3885 — 5y
0
I think I get it now. I'll try again. Ma02rc 4 — 5y
0
After rewriting and retrying the script multiple times, I fail to get a proper solution to the issue, as I keep getting the same result of the third picture. I will need more information on how to properly insert the line of code into the script. For now I will keep this question as unresolved. Ma02rc 4 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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

0
Thanks! I'll try that and get back to you. Ma02rc 4 — 5y
0
Unfortunetly, that did not work. Ma02rc 4 — 5y
0
I just edited the post with the code sample and what happened when I ran the script. Ma02rc 4 — 5y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

Answer this question