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

Math random script doesn't work properly?

Asked by
Primpy 25
9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

Greetings to the readers. Unfortunately I encountered a problem while editing a script.

Original script (The only thing I edited was this part):

local Suit = game.Lighting.Morphs:findFirstChild(script.Parent.Suit.Value)

Edited script:

function change()

num = math.random(1, 2)

if num == 1 then
local Suit = game.Lighting.Morphs:findFirstChild(script.Parent.Suit.Value)
end

if num == 2 then
local Suit = game.Lighting.Morphs:findFirstChild(script.Parent.Suit2.Value)
end

end

I also tried removing the "local" stuff, but I just can't get it to work. I'm a begginer when it comes to scripting. If someone does figure out the problem, please give me an answer :) I'll post the entire script too, just in case.

local Suit = game.Lighting.Morphs:findFirstChild(script.Parent.Suit.Value)
local Me = script.Parent.Parent.Parent.Parent.Character
local Weapon = game.Lighting.Moves:findFirstChild(script.Parent.Weapon.Value)
local Weapon2 = game.Lighting.Moves:findFirstChild(script.Parent.Weapon2.Value)

function Click(mouse)
script.Parent.Visible = false
    if Me:findFirstChild("Humanoid") ~= nil then
Me:findFirstChild("Arm1"):remove()
Me:findFirstChild("Arm2"):remove()
Me:findFirstChild("Leg1"):remove()
Me:findFirstChild("Leg2"):remove()
Me:findFirstChild("Chest"):remove()
Me.Torso.Anchored = true
local bul = Instance.new("Part") 
bul.formFactor = "Symmetric"
bul.Shape = "Ball" 
f = script.Parent.Fire
f:clone().Parent = bul
bul.Size = Vector3.new(4,4,4) 
bul.BrickColor = BrickColor.new("White") 
bul.Transparency = 0
bul.Reflectance = 0.5
bul.CanCollide = false 
bul.Anchored = true
bul.TopSurface = 0 
bul.BottomSurface = 0 
bul.CFrame = Me.Torso.CFrame * CFrame.new(0,0,0) 
bul.Parent = Me
local bulm = Instance.new("SpecialMesh") 
bulm.Scale = Vector3.new(1, 1, 1)
bulm.Parent = bul 
bulm.MeshType = "Brick" 
game:GetService("Debris"):AddItem(bul, 1.5) 
for i = 1 , 10 do
bul.Size = bul.Size + Vector3.new(1,0,1) 
bul.CFrame = Me.Torso.CFrame * CFrame.new(0,0,0) 
wait(0.001)
end
Me.Torso.Anchored = false
        local g = Suit.Arm1:clone()
        g.Parent = Me
        local C = g:GetChildren()
        for i=1, #C do
            if C[i].className == "Part" then
                local W = Instance.new("Weld")
                W.Part0 = g.Middle
                W.Part1 = C[i]
                local CJ = CFrame.new(g.Middle.Position)
                local C0 = g.Middle.CFrame:inverse()*CJ
                local C1 = C[i].CFrame:inverse()*CJ
                W.C0 = C0
                W.C1 = C1
                W.Parent = g.Middle
            end
                local Y = Instance.new("Weld")
                Y.Part0 = Me["Left Arm"]
                Y.Part1 = g.Middle
                Y.C0 = CFrame.new(0, 0, 0)
                Y.Parent = Y.Part0
        end

        local h = g:GetChildren()
        for i = 1, # h do
            h[i].Anchored = false
            h[i].CanCollide = false
        end

    end

    if Me:findFirstChild("Humanoid") ~= nil and Me:findFirstChild("Arm2") == nil then
        local g = Suit.Arm2:clone()
        g.Parent = Me
        local C = g:GetChildren()
        for i=1, #C do
            if C[i].className == "Part" then
                local W = Instance.new("Weld")
                W.Part0 = g.Middle
                W.Part1 = C[i]
                local CJ = CFrame.new(g.Middle.Position)
                local C0 = g.Middle.CFrame:inverse()*CJ
                local C1 = C[i].CFrame:inverse()*CJ
                W.C0 = C0
                W.C1 = C1
                W.Parent = g.Middle
            end
                local Y = Instance.new("Weld")
                Y.Part0 = Me["Right Arm"]
                Y.Part1 = g.Middle
                Y.C0 = CFrame.new(0, 0, 0)
                Y.Parent = Y.Part0
        end

        local h = g:GetChildren()
        for i = 1, # h do
            h[i].Anchored = false
            h[i].CanCollide = false
        end

    end

    if Me:findFirstChild("Humanoid") ~= nil and Me:findFirstChild("Leg1") == nil then
        local g = Suit.Leg1:clone()
        g.Parent = Me
        local C = g:GetChildren()
        for i=1, #C do
            if C[i].className == "Part" then
                local W = Instance.new("Weld")
                W.Part0 = g.Middle
                W.Part1 = C[i]
                local CJ = CFrame.new(g.Middle.Position)
                local C0 = g.Middle.CFrame:inverse()*CJ
                local C1 = C[i].CFrame:inverse()*CJ
                W.C0 = C0
                W.C1 = C1
                W.Parent = g.Middle
            end
                local Y = Instance.new("Weld")
                Y.Part0 = Me["Left Leg"]
                Y.Part1 = g.Middle
                Y.C0 = CFrame.new(0, 0, 0)
                Y.Parent = Y.Part0
        end

        local h = g:GetChildren()
        for i = 1, # h do
            h[i].Anchored = false
         h[i].CanCollide = false
        end

    end

    if Me:findFirstChild("Humanoid") ~= nil and Me:findFirstChild("Leg2") == nil then
        local g = Suit.Leg2:clone()
        g.Parent = Me
        local C = g:GetChildren()
        for i=1, #C do
            if C[i].className == "Part" then
                local W = Instance.new("Weld")
                W.Part0 = g.Middle
                W.Part1 = C[i]
                local CJ = CFrame.new(g.Middle.Position)
                local C0 = g.Middle.CFrame:inverse()*CJ
                local C1 = C[i].CFrame:inverse()*CJ
                W.C0 = C0
                W.C1 = C1
                W.Parent = g.Middle
            end
                local Y = Instance.new("Weld")
                Y.Part0 = Me["Right Leg"]
                Y.Part1 = g.Middle
                Y.C0 = CFrame.new(0, 0, 0)
                Y.Parent = Y.Part0
        end

        local h = g:GetChildren()
        for i = 1, # h do
            h[i].Anchored = false
         h[i].CanCollide = false
        end

    end
    if Me:findFirstChild("Humanoid") ~= nil and Me:findFirstChild("Chest") == nil then
        local g = Suit.Chest:clone()
        g.Parent = Me
        local C = g:GetChildren()
                local R = Me:GetChildren()
        for i=1, #R do
            if R[i].className == "Hat" then
                R[i]:remove()
            end
        end
        for i=1, #C do
            if C[i].className == "Part" then
                local W = Instance.new("Weld")
                W.Part0 = g.Middle
                W.Part1 = C[i]
                local CJ = CFrame.new(g.Middle.Position)
                local C0 = g.Middle.CFrame:inverse()*CJ
                local C1 = C[i].CFrame:inverse()*CJ
                W.C0 = C0
                W.C1 = C1
                W.Parent = g.Middle
            end
                local Y = Instance.new("Weld")
                Y.Part0 = Me.Torso
                Y.Part1 = g.Middle
                Y.C0 = CFrame.new(0, 0, 0)
                Y.Parent = Y.Part0
        end

        local h = g:GetChildren()
        for i = 1, # h do
            h[i].Anchored = false
            h[i].CanCollide = false
        end

    end
end

script.Parent.MouseButton1Down:connect(Click)

















local debounce = false
local Me2 = script.Parent.Parent.Parent.Parent.Backpack
local evolve = game.Lighting.None

function getPlayer(humanoid) 
local players = game.Players:children() 
for i = 1, #players do 
if players[i].Character.Humanoid == humanoid then return players[i] end 
end 
return nil 
end 



function Click2(mouse)

local human = Me:findFirstChild("Humanoid") 
if (human ~= nil) and debounce == false then

debounce = true

local player = getPlayer(human) 

if (player == nil) then return end 

evolve:clone().Parent = Me2.Parent.PlayerGui
Weapon:clone().Parent = Me2
Weapon2:clone().Parent = Me2

debounce = false
Me.Speed.Value = script.Parent.Speed.Value
wait(0.1)
human.WalkSpeed = script.Parent.Speed.Value
human.MaxHealth = script.Parent.Health.Value
human.Health = script.Parent.Health.Value
Me.Shirt:remove()
Me.Pants:remove()
end


end


script.Parent.MouseButton1Down:connect(Click2)

0
What exactly is broken in this? YellowoTide 1992 — 9y
0
The full script is inside a gui. Once the gui is pressed, it morphs you in the model with the same name as the "Suit" value from game.Lightning.Morphs. When I press the gui, nothing happens at all. Primpy 25 — 9y

1 answer

Log in to vote
0
Answered by
Primpy 25
9 years ago

Problem was fixed.

Suit = game.Lighting.Morphs:findFirstChild(script.Parent.Suit.Value)

function change()

num = math.random(1, 2)

if num == 1 then
Suit = game.Lighting.Morphs:findFirstChild(script.Parent.Suit.Value)
end

if num == 2 then
Suit = game.Lighting.Morphs:findFirstChild(script.Parent.Suit2.Value)
end

end
Ad

Answer this question