✓ Accepted answer
First, let's make the code cleaner. Here's what I did:
- Define the function at the top; now the loopy code is really tiny
- Tab everything correctly
- Eliminate pointless
:FindFirstChild (don't use :FindFirstChild when you aren't actually checking if the result is nil)
- Eliminate pointless
if workspace:WaitForChild -- :WaitForChild can't return nil. We can just eliminate that whole if
game.Workspace.ActiveCamera should just be Camera, we have the variable for it
- Change
catbounce to a meaningful name, declare it at the top, start as true
- Join the two
if checks in the for loop by using and
local canClick = true
function click(v)
if canClick and P.Name == game.Workspace.GameMaster.Value then
canClick = false
wait()
local Camera = workspace:WaitForChild("ActiveCamera")
Camera.CFrame = CFrame.new(Camera.Position)
+ Vector3.new(tonumber(v.Value.Value))
print("Moved to " .. tostring(Camera.Position))
print("Added " .. tostring( tonumber(v.Value.Value) ) )
wait(.25)
canClick = true
end
end
for i, v in pairs(script.Parent:GetChildren()) do
if v.Name ~= "Fire" and v:IsA("TextButton") then
v.MouseButton1Click:connect(function() click(v) end)
end
end
Now this is much easier to read and understand.
I'm guessing the issue is that tonumber(v.Value.Value) is nil. Vector3.new(nil) will be the same as Vector3.new(), which is Vector3.new(0, 0, 0); translating by the origin won't do anything.
Note that if you give Vector3.new just one number it will use it as the x value, and the other two (y (up), z) will be 0.
Look at what is printed if you use
print(v.Value.Value, tonumber(v.Value.Value) )
tonumber will return nil if the string isn't actually a number (e.g. tonumber("5c") or tonumber("c5") will return nil)
You also probably shouldn't be using CFrame.new(Camera.Position); that will eliminate any rotation that the camera had before. Instead use this (it's briefer too)
Camera.CFrame = Camera.CFrame + Vector3.new(tonumber(v.Value.Value))
EDIT
If you claim that v.Value.Value is a Vector3, you definitely shouldn't be using tonumber or Vector3.new with it. Just use v.Value.Value!
2 comments
Vector3 scale takes 3 arguments, you only supplied one.
Value.Value is a Vector3 value item