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

Why isnt the script i made is not changing the brick's position not working?

Asked by
656339 -3
6 years ago

I was trying to write a script that changes the position of the brick in the Workspace called test1. When the parent of the script is hitten by the player, test1 was supposed to change it's X, Y and Z values which is in the Position section of the part's properties. Please help! The script is here:

local Part = script.Parent
local X = game.Workspace.test1.Position.X
local Y = game.Workspace.test1.Position.Y
local Z = game.Workspace.test1.Position.Z
Part.Touched:connect(function(hit)
 local H = hit.Parent:FindFirstChild("Humanoid")
 if H then
  wait(0.05)
  X = -30.545 
  Y = 6.71
  Z = -5
  wait(0.05)
  X = -30.545 
  Y = 6.71
  Z = -6
  wait(0.05)
  X = -30.545 
  Y = 6.71
  Z = -7
  wait(0.05)
  X = -30.545 
  Y = 6.71
  Z = -8.5
  wait(0.05)
  X = -30.545 
  Y = 6.71
  Z = -9
  wait(0.05)
  X = -30.545 
  Y = 6.71
  Z = -10
  wait(0.05)
  X = -30.545 
  Y = 6.71
  Z = -11
  wait(0.05)
  X = -30.545 
  Y = 6.71
  Z = -12
  wait(0.05)
  X = -30.545 
  Y = 6.71
  Z = -13
  wait(0.05)
  X = -30.545 
  Y = 6.71
  Z = -14
  wait(0.05)
  X = -30.545 
  Y = 6.71
  Z = -15
  wait(0.05)
  X = -30.545 
  Y = 6.71
  Z = -16
  wait(0.05)
  X = -30.545 
  Y = 6.71
  Z = -17
 end
end)
0
You are changing the variables, not the position Vulkarin 581 — 6y
0
Can someone teach me how to script at lua bc i need it for my games RidiculousBox -6 — 6y

2 answers

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago

When you are going

local X = game.Workspace.test1.Position.X

You are just recording the position as a variable, and as Vulkarin said, are only changing the value of the variable instead of the position. To set the x,y and z of the position, you can go:

game.Workspace.test1.Position = Vector3.new(-30.545,6.71,-5)

or

game.Workspace.test1.CFrame = CFrame.new(-30.545,6.71,-5)

to ignore collisions.

However, if you just want to move the part on the Z axis 12 times, you can use a for loop:

for i = 1,12 do
    workspace.test1.CFrame = workspace.test1.CFrame + Vector3.new(0,0,-1)
    wait(0.05)
end
Ad
Log in to vote
0
Answered by 6 years ago

This is what I would do and it would save you the trouble of having to write the entire thing again and again. For future reference if you are going to be repeating something a set amount of times I would use the for loop. Also to check if the part has a humanoid do not set a variable as that can throw an error just do if hit.Parent:FindFirstChild("Humanoid") Change your script to this if you want:

local Part = script.Parent
local test1 = game.Workspace.test1
Part.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        for i =1,12 do
            wait(0.05)
            test1.Position = test1.Position + UDim2.new(0,-1,0)
        end
    end
end)

Hope it helped :D

Answer this question