1

I'm trying to make walls to change size based on the distance from the player's torso (bigger when close, smaller when faraway). I'm not really good at this kind of stuff so I have no idea how to do this.

Here's the code at the moment:

for _, v in pairs(script.Parent:GetChildren()) do
    if string.sub(v.Name,1,4) == "Wall" then
        local walls = {}
        walls[v] = v.CFrame
        for x,y in pairs(walls) do
            print(x,y)
        end
        local startCFrame = v.CFrame
        game:GetService("RunService").RenderStepped:connect(function()
            v.Size = v.Size + Vector3.new(0,(workspace["Player"].Torso.Position-v.Position).magnitude,0)
            v.CFrame = walls[v] * CFrame.new(0,v.Size.Y/2-(script.Parent.Floor.Size.Y/2),0)
        end)    
    end
end

if you're wondering why im changing the cframe of v, it's so that when the player walks over the brick or into the side of it, it won't go above the player, but stay in the same position it originally was

Ducktor
  • 337
  • 1
  • 9
  • 27
  • 1
    Your code makes no sense. I'm sure it does not even run without errors because of how you use v. It cannot be a key and a table at the same time. So please add more information on what the code should do and what you get instead. – Piglet Apr 17 '16 at 14:25
  • It works fine, otherwise I wouldn't of posted it. v is the children of the scripts parent. Creating a dictionary is like this table[key] = value. More information [here](http://wiki.roblox.com/index.php?title=Table&redirect=no#Indexing_a_dictionary). Also, this is a modified version of lua done by the ROBLOX team – Ducktor Apr 17 '16 at 14:34
  • Ah, it seems I used v again in another for loop, which may cause confusing. Fixed it. – Ducktor Apr 17 '16 at 14:40
  • no I simply did not know that you can use tables as keys. I never thought about it because it does not make any sense and I'm sure I never read about it either. reusing v is fine as it will be another v inside the inner for loop. but your loop does not make sense as walls has only 1 element – Piglet Apr 17 '16 at 14:45
  • Walls will have 4 things, since there's 4 parts with Wall at the start of the name. [Here's a gif of what's happening in-game](http://imgur.com/zaC20b8) (ignore the green artifacting, it's just gifcam messing up). I completely removed the distance checking because all it did was resize all of them to the max size (2048) instantly. I just need the equation/whatever for making this work – Ducktor Apr 17 '16 at 15:04

0 Answers0