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

How do you make a script where when you spawn, you spawn sized 0.5?

Asked by
mrn07 0
6 years ago
Edited 6 years ago

I've tried local scripts, i've tried to size the body parts differently, nothing works!

I want this script to be when you spawn in, you will be sized 0.5 like in Kohl's Admin Commands.

no-one has tutorials on this and I really need this to be done. an example script i've tried:

function onPlayerEntered (newPlayer) wait (5) newPlayer.Character.Torso.Size = 0.5, 1, 0.5 newPlayer.Character.Head.Size = 0.5, 0.5, 0.5 newPlayer.Character.leftArm.Size = 0.5, 1, 0.5 newPlayer.Character.rightArm.Size = 0.5, 1, 0.5 newPlayer.Character.leftLeg.Size = 0.5, 1, 0.5 end

game.Players.PlayerAdded:connect (onPlayerEntered) (DOES NOT WORK.)

By the way someone referred this to me, it was a model. I am not used to scripting like this.

An example of the spawn-sizing script I want is this: https://gyazo.com/12c6c24ab7937b962e0876ffd50e8ff3

Little Angels Daycare has a script like this.

I have tried another code, but it worked to no avail. It messed up my game entirely.

0
Please put your code in code blocks. It makes it much easier to read! hiimgoodpack 2009 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

The reason why your current script doesn't work is because it doesn't recognize the number values. The size variable for the character parts are defined as a Vector3, so you have to create a new vector for each part.

function onPlayerEntered (newPlayer) 
    wait (5) 
    newPlayer.Character.Torso.Size = Vector3.new(0.5, 1, 0.5) 
    newPlayer.Character.Head.Size = Vector3.new(0.5, 1, 0.5)  
    newPlayer.Character.leftArm.Size = Vector3.new(0.5, 1, 0.5)  
    newPlayer.Character.rightArm.Size = Vector3.new(0.5, 1, 0.5)  
    newPlayer.Character.leftLeg.Size = Vector3.new(0.5, 1, 0.5) 
end

game.Players.PlayerAdded:connect (onPlayerEntered)

This however only resizes each part to what is defined, and doesn't exactly scale your model as you think it would. To actually do that, it would require a lot more coding which is out of my scripting knowledge.

0
Yeah i can see that. Thank you for the information! :) mrn07 0 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

CREDITS: CloneTrooper1019

function scaleCharacter(model,scale)
    wait()
    if not model or not scale then return end
    if not _G.ScaleCons then
        _G.ScaleCons = {}
    end
    if _G.ScaleCons[model] then
        _G.ScaleCons[model]:disconnect()
    end
    local joints = {}
    local parts = {}
    local h = model:findFirstChild("Humanoid")
    if h then
        h.Parent = nil
    end
    local function handleHat(hat)
        if hat:findFirstChild("GotScaled") then return end
        Instance.new("Flag",hat).Name = "GotScaled"
        Spawn(function ()
            local h = hat:WaitForChild("Handle")
            local m = h:WaitForChild("Mesh")
            m.Scale = m.Scale * scale
        end)
        local yInc = (scale-1)*.5
        hat.AttachmentPos = (hat.AttachmentPos * scale) - (hat.AttachmentUp * Vector3.new(yInc,yInc,yInc))
    end
    for _,v in pairs(model:GetChildren()) do
        if v:IsA("BasePart") then
            table.insert(parts,v)
            v.Anchored = true;
            v.FormFactor = "Custom";
            for _,j in pairs(v:GetChildren()) do
                if j:IsA("Motor6D") then
                    local t = {
                        Name = j.Name;
                        Parent = v;
                        Part0 = j.Part0;
                        Part1 = j.Part1;
                        C0 = j.C0;
                        C1 = j.C1;
                    }
                    table.insert(joints,t)
                    j:Destroy()
                end
            end
        elseif v:IsA("Hat") then
            handleHat(v)
        end
    end
    for _,v in pairs(parts) do
        v.Size = v.Size * scale
        v.Anchored = false
    end
    for _,j in pairs(joints) do
        local c0 = {j.C0:components()}
        local c1 = {j.C1:components()}
        for i = 1,3 do
            c0[i] = c0[i] * scale
            c1[i] = c1[i] * scale
        end
        j.C0 = CFrame.new(unpack(c0))
        j.C1 = CFrame.new(unpack(c1))
        local n = Instance.new("Motor6D")
        for k,v in pairs(j) do
            n[k] = v
        end
    end
    model.ChildAdded:connect(function (c)
        if c:IsA("Hat") then
            handleHat(c)
        end
    end)
    if h then
        h.Parent = model
        h.WalkSpeed = 16 * scale
        h.MaxHealth = 100 * scale
        h.Health = (h.Health/h.MaxHealth)*(100*scale)
    end
    _G.ScaleCons[model] = con
end
game.Players.PlayerAdded:connect(function (player)
    player.CharacterAdded:connect(function (character)
        scaleCharacter(player.Character, .5)
    end)
end)

Answer this question