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

Problems with assigning to X?

Asked by
Mystdar 352 Moderation Voter
9 years ago

I am trying to make a cobblestone script, that puts lots of Stones on a part in a cobblestone-like arrangement, they are 3 bricks long, 1 high, 1 deep. It says

function Cobblestone(Part)
    local Position_X = Part.Position.X
    local Position_Y = Part.Position.Y  
    local Position_Z = Part.Position.Z

    local Width = Part.Size.X
    local Height = Part.Size.Y
    local Length = Part.Size.Z

    local Rotation_X = Part.Rotation.X
    local Rotation_Y = Part.Rotation.Y  
    local Rotation_Z = Part.Rotation.Z

    local Starting_Point_X = Position_X - (Width/2) -- Far side
    local Starting_Point_Z = Position_Z - (Length/2) -- Far Side

    local Across = math.floor(Width/3) -- How many stones, per row (3 studs long)
    local Depth = math.floor(Length) -- How many Columns of stones

    for a = 0, Depth do 
        for b = 0, Length do
            local Stone = game.Lighting.Stone:Clone()
            Stone.Position.X = (Starting_Point_X + 0.2) + b*1.5  -- Bottom Corner + 0.2 + Half the Stones' width
            Stone.Position.Y = Position_Y + (Height/2) + 0.3 -- 0.3 studs above the surface of the part
            Stone.Position.Z = (Starting_Point_Z + 0.2) + a*1.2 -- Moving back after 7 times

            Stone.Rotation.X = Rotation_X + math.random(-2, 2)
            Stone.Rotation.Y = Rotation_Y + math.random(-2, 2)
            Stone.Rotation.Z = Rotation_Z + math.random(-2, 2)

            Stone.Anchored   = true
        end
    end
end

Cobblestone(game.Workspace.Path)

Output:

11:38:35.374 - X cannot be assigned to

11:38:35.375 - Script 'Workspace.Stoning', Line 23 - global Cobblestone

11:38:35.376 - Script 'Workspace.Stoning', Line 36

11:38:35.376 - Stack End

1 answer

Log in to vote
1
Answered by
noliCAIKS 210 Moderation Voter
9 years ago

The properties are "read-only", as it's called; this means they cannot be changed. However, it is possible to set the Position or Rotation property to a new Vector3. So you should create a new Vector3 with the X, Y and Z that you want, instead of trying to change it in the old vector. In other words, do this:

local Stone = game.Lighting.Stone:Clone()
Stone.Position = Vector3.new(
    (Starting_Point_X + 0.2) + b*1.5,  -- Bottom Corner + 0.2 + Half the Stones' width
    Position_Y + (Height/2) + 0.3, -- 0.3 studs above the surface of the part
    (Starting_Point_Z + 0.2) + a*1.2) -- Moving back after 7 times
Stone.Rotation = Vector3.new(
    Rotation_X + math.random(-2, 2),
    Rotation_Y + math.random(-2, 2),
    Rotation_Z + math.random(-2, 2))

Instead of Stone.Position.X = ..., Stone.Position.Y = ..., etc.

Ad

Answer this question