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

Why aren't my blocks sticking to my body?

Asked by 9 years ago

Here's my code.

local enabled = true
Player = script.Parent.Parent
mouse = Player:GetMouse()
run = game:GetService("RunService")
local Left_Arm = script.Parent:FindFirstChild("Left Arm")
local Right_Arm = script.Parent:FindFirstChild("Right Arm")
local Core = script.Parent:FindFirstChild("Torso")
local Left_Leg = script.Parent:FindFirstChild("Left Leg")
local Right_Leg = script.Parent:FindFirstChild("Right Leg")
function onKeyDown(key)
    key = key:lower()
    if key == "t" then
        game:GetService("Chat"):Chat(Player.Character.Head, "Focus the mind, reflect upon yourself, and determine the goal.")
        Left_Arm = Instance.new ("Part")
        Right_Arm = Instance.new("Part")
        Core = Instance.new("Part")
        Left_Leg = Instance.new("Part")
        Right_Leg = Instance.new("Part")
        Left_Arm.BrickColor = BrickColor.new("White")
        Left_Arm.Size = Vector3.new(2, 3, 2)
        Left_Arm.TopSurface = "Smooth"
        Left_Arm.BottomSurface = "Smooth"
        Left_Arm.Transparency = 0.7
        Left_Arm.CanCollide = false
        Left_Arm.CFrame = Player.Character["Left Arm"].CFrame *CFrame.new(0, 0, 0)
        Left_Arm.Parent = workspace
        Right_Arm.BrickColor = BrickColor.new("White")
        Right_Arm.Size = Vector3.new(2, 3, 2)
        Right_Arm.TopSurface = "Smooth"
        Right_Arm.BottomSurface = "Smooth"
        Right_Arm.Transparency = 0.7
        Right_Arm.CanCollide = false
        Right_Arm.CFrame = Player.Character["Right Arm"].CFrame *CFrame.new(0, 0, 0)
        Right_Arm.Parent = workspace
        Core.BrickColor = BrickColor.new("White")
        Core.Size = Vector3.new(3, 3, 2)
        Core.TopSurface = "Smooth"
        Core.BottomSurface = "Smooth"
        Core.Transparency = 0.7
        Core.CanCollide = false
        Core.CFrame = Player.Character["Torso"].CFrame *CFrame.new(0, 0, 0)
        Core.Parent = workspace
        Left_Leg.BrickColor = BrickColor.new ("White")
        Left_Leg.Size = Vector3.new(2, 3, 2)
        Left_Leg.TopSurface = "Smooth"
        Left_Leg.BottomSurface = "Smooth"
        Left_Leg.Transparency = 0.7
        Left_Leg.CanCollide = false
        Left_Leg.CFrame = Player.Character["Left Leg"].CFrame *CFrame.new(0, 0, 0)
        Left_Leg.Parent = workspace
        Right_Leg.BrickColor = BrickColor.new("White")
        Right_Leg.Size = Vector3.new(2, 3, 2)
        Right_Leg.TopSurface = "Smooth"
        Right_Leg.BottomSurface = "Smooth"
        Right_Leg.Transparency = 0.7
        Right_Leg.CanCollide = false
        Right_Leg.CFrame = Player.Character["Right Leg"].CFrame *CFrame.new(0, 0, 0)
        Right_Leg.Parent = workspace
        local weld = Instance.new("Weld")
        weld.Part0 = Left_Arm
        weld.C0 = Left_Arm.CFrame:inverse()
        weld.Part1 = script.Parent:FindFirstChild("Left Arm")
        weld.Parent = script.Parent 
        local weld2 = Instance.new("Weld")
        weld2.Part0 = Right_Arm
        weld2.C0 = Right_Arm.CFrame:inverse()
        weld2.Part1 = script.Parent:FindFirstChild("Right Arm")
        weld2.Parent = script.Parent 
        local weld3 = Instance.new("Weld")
        weld3.Part0 = Core
        weld3.C0 = Core.CFrame:inverse()
        weld3.Part1 = script.Parent:FindFirstChild("Torso")
        weld3.Parent = script.Parent 
        local weld4 = Instance.new("Weld")
        weld4.Part0 = Left_Leg
        weld4.C0 = Left_Leg.CFrame:inverse()
        weld4.Part1 = script.Parent:FindFirstChild("Left Leg")
        weld4.Parent = script.Parent 
        local weld5 = Instance.new("Weld")
        weld5.Part0 = Right_Leg
        weld5.C0 = Right_Leg.CFrame:inverse()
        weld5.Part1 = script.Parent:FindFirstChild("Right Leg")
        weld5.Parent = script.Parent    
    end
end

mouse.KeyDown:connect(onKeyDown)

The blocks won't obey the code which god created....LUA.

0
Do the parts actually spawn but not stick? (Welds may not work) or do the Parts not spawn? Look in the Output, and I believe workspace on line 50 and 58 should have a capital W Mystdar 352 — 9y
0
They spawn and just don't stick. kingalpha1 15 — 9y

1 answer

Log in to vote
0
Answered by
Discern 1007 Moderation Voter
9 years ago

Now I'm terrible with Welds, but I'm pretty sure I have the correct solution.

This is happening multiple times in the script, but let's just take lines 59-63 as an example.

You setting the script's parent last. If you look at line 62, you're trying to access "script.Parent". The problem is, you have not set the parent at that time (You do in Line 63). Basically, you're trying to access its parent that doesn't exist. You need to set the script's parent before you try to access its parent.

You probably already know this, but Instance.new() has another argument. The first one is deciding what you are inserting, the second argument sets its parent. So really you can merge the creation line and parental assigning line into 1 function. Here is the fixed script:

local enabled = true
Player = script.Parent.Parent
mouse = Player:GetMouse()
run = game:GetService("RunService")
local Left_Arm = script.Parent:FindFirstChild("Left Arm")
local Right_Arm = script.Parent:FindFirstChild("Right Arm")
local Core = script.Parent:FindFirstChild("Torso")
local Left_Leg = script.Parent:FindFirstChild("Left Leg")
local Right_Leg = script.Parent:FindFirstChild("Right Leg")
function onKeyDown(key)
    key = key:lower()
    if key == "t" then
        game:GetService("Chat"):Chat(Player.Character.Head, "Focus the mind, reflect upon yourself, and determine the goal.")
        Left_Arm = Instance.new ("Part")
        Right_Arm = Instance.new("Part")
        Core = Instance.new("Part")
        Left_Leg = Instance.new("Part")
        Right_Leg = Instance.new("Part")
        Left_Arm.BrickColor = BrickColor.new("White")
        Left_Arm.Size = Vector3.new(2, 3, 2)
        Left_Arm.TopSurface = "Smooth"
        Left_Arm.BottomSurface = "Smooth"
        Left_Arm.Transparency = 0.7
        Left_Arm.CanCollide = false
        Left_Arm.CFrame = Player.Character["Left Arm"].CFrame *CFrame.new(0, 0, 0)
        Left_Arm.Parent = workspace
        Right_Arm.BrickColor = BrickColor.new("White")
        Right_Arm.Size = Vector3.new(2, 3, 2)
        Right_Arm.TopSurface = "Smooth"
        Right_Arm.BottomSurface = "Smooth"
        Right_Arm.Transparency = 0.7
        Right_Arm.CanCollide = false
        Right_Arm.CFrame = Player.Character["Right Arm"].CFrame *CFrame.new(0, 0, 0)
        Right_Arm.Parent = workspace
        Core.BrickColor = BrickColor.new("White")
        Core.Size = Vector3.new(3, 3, 2)
        Core.TopSurface = "Smooth"
        Core.BottomSurface = "Smooth"
        Core.Transparency = 0.7
        Core.CanCollide = false
        Core.CFrame = Player.Character["Torso"].CFrame *CFrame.new(0, 0, 0)
        Core.Parent = workspace
        Left_Leg.BrickColor = BrickColor.new ("White")
        Left_Leg.Size = Vector3.new(2, 3, 2)
        Left_Leg.TopSurface = "Smooth"
        Left_Leg.BottomSurface = "Smooth"
        Left_Leg.Transparency = 0.7
        Left_Leg.CanCollide = false
        Left_Leg.CFrame = Player.Character["Left Leg"].CFrame *CFrame.new(0, 0, 0)
        Left_Leg.Parent = workspace
        Right_Leg.BrickColor = BrickColor.new("White")
        Right_Leg.Size = Vector3.new(2, 3, 2)
        Right_Leg.TopSurface = "Smooth"
        Right_Leg.BottomSurface = "Smooth"
        Right_Leg.Transparency = 0.7
        Right_Leg.CanCollide = false
        Right_Leg.CFrame = Player.Character["Right Leg"].CFrame *CFrame.new(0, 0, 0)
        Right_Leg.Parent = workspace
        local weld = Instance.new("Weld", script.Parent)
        weld.Part0 = Left_Arm
        weld.C0 = Left_Arm.CFrame:inverse()
        weld.Part1 = script.Parent:FindFirstChild("Left Arm")
        local weld2 = Instance.new("Weld", script.Parent)
        weld2.Part0 = Right_Arm
        weld2.C0 = Right_Arm.CFrame:inverse()
        weld2.Part1 = script.Parent:FindFirstChild("Right Arm")
        local weld3 = Instance.new("Weld", script.Parent)
        weld3.Part0 = Core
        weld3.C0 = Core.CFrame:inverse()
        weld3.Part1 = script.Parent:FindFirstChild("Torso")
        local weld4 = Instance.new("Weld", script.Parent)
        weld4.Part0 = Left_Leg
        weld4.C0 = Left_Leg.CFrame:inverse()
        weld4.Part1 = script.Parent:FindFirstChild("Left Leg")
        local weld5 = Instance.new("Weld", script.Parent)
        weld5.Part0 = Right_Leg
        weld5.C0 = Right_Leg.CFrame:inverse()
        weld5.Part1 = script.Parent:FindFirstChild("Right Leg") 
    end
end

mouse.KeyDown:connect(onKeyDown)

Hope I helped. :)

Ad

Answer this question