Unable to assign property CFrame. CoordinateFrame expected, got Vector3 - lua

So, I was trying to make that it scans everything in user's body and if it's called humanoidRootPart, it will save the the position. Instead of it i got the error 'Unable to assign property CFrame. CoordinateFrame expected, got Vector3'
for i,v in pairs(plrChar:GetChildren()) do
if v.Name == "HumanoidRootPart" then
game:GetService('ReplicatedStorage').savedPos.Value = Vector3.new(v.Position)
end
end

If savedpos is a CFrame Value, instead of just assigning it's Value to "Vector3.new(v.Position)" (which is already redundant as "Position" is already a Vector3) you should use "CFrame.new(v.Position)"

Related

My number value isn't updating, how do I fix it?

So I was trying to make it so that every second the loop changed the value of the number value but it keeps returning either nil or 0. I tried adding it as a local value that affected the actual value and a few other things like making it a string instead and replacing the string with a new one but that still didn't return anything. This is my code now and it's the code that returns 0 and not nil or an error.
local SecondsAfterGameStart = game.ServerStorage.SecondsAfterGameStart.Value
while true do
wait(0.1)
SecondsAfterGameStart = SecondsAfterGameStart + 1
end
When you save SecondsAfterGameStart.Value into a local variable, you are not keeping a reference to the original NumberValue object, you are copying its value into the local variable. Later in your while loop, you are accessing and modifying a variable and not the original object, so changes are never saved back to the object in the ServerStorage.
So, instead of saving the Value, hold onto the entire NumberValue itself. Then you can update the Value directly.
local SecondsAfterGameStart = game.ServerStorage.SecondsAfterGameStart
while true do
wait(0.1)
SecondsAfterGameStart.Value = SecondsAfterGameStart.Value + 1
end

Checking if an instance *doesn't* exist -> "Not a valid member"

"checkin is not a valid member of PlayerGui" at line 2
function onClick(plr)
if game.Players[plr.Name].PlayerGui.checkin ~= nil then
print('player already has gui')
else
if game.ServerStorage.Players[plr.Name].Value == 0 then
local gui = game.ServerStorage.GUIs.checkin:Clone()
gui.Parent = plr.PlayerGui
print('fresh gui being handed to '.. plr.Name)
end
end
end
script.Parent.ClickDetector.MouseClick:connect(onClick)
If a member doesn't exist on an instance, Roblox will immediately throw an error.
If you're not sure if a child of a given name exists, use :FindFirstChild(name). Rather than throw an error, it just returns nil.
Note that MouseClick already gives a player, so doing game.Players[plr.Name] is really redundant.
if plr.PlayerGui:FindFirstChild("checkin") then
It's best practice to not handle GUIs on the Server. Instead, you can communicate to LocalScripts what they need to show using RemoteFunctions/RemoteEvents.

In Corona SDK, why is object.X nil when a value is assigned?

I did some research prior to posting this question. But, I couldn't find a clear answer so I decided to post it. Basically, I'm trying to get a rectangular object move across the screen by changing the x position. But, I can't perform the function because I am receiving an error saying that "brick01.X is nil." Any ideas?
local brick01 = display.newRect(_W/2,math.random(1,8)*32,50,32)
--brick01.anchorX = 0
--brick01.anchorY = 0
brick01:setFillColor(0,0,0)
print(brick01.X) -- Returns Nil
local function update(event)
updateBackgrounds()
end
function updateBackgrounds()
--far background movement
brick01.X = brick01.X - (4)
end
timer.performWithDelay(1,update,-1)
You have to use brick01.x not brick01.X.

Checking if a table has been created not working

Using the code:
function createNewBody(name,mass)
if not world.body[name]==nil then
print("This body has already been created. Maybe you meant to update it's values?\n")
else
world.body[name]={mass=m,x=0,y=0,xAccel=0,yAccel=0,xR=0,yR=0,properties={gaseous=false,texture=""}}
world.bodies=world.bodies+1
end
end
This code shows no errors, but when I bind createNewBody(moon,1.622) to a key and then use it, it lets me spam the key without showing the error message.
And, yes, I have defined world.bodies and world.body
not world.body[name]==nil is parsed as (not world.body[name])==nil. Since the result of not is a boolean, it is never nil.
Try not(world.body[name]==nil) or world.body[name]~=nil.

attempt to call a nil value

for i = 1, groupA:getNumChildren() do
local sprite = groupA:getChildAt(i)
if cute.anim[1]:collidesWith(sprite) then
youLoose()
end
end
local function youLoose()
local font3 = TTFont.new("billo.ttf", 20, " 1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,?")
local text7 = TextField.new(font2, "gameover")
text7:setPosition(200, 100)
stage:addChild(text7)
GameLost = Bitmap.new(Texture.new("gameover.jpg"))
Background : removeFromParent()
groupA : removeFromParent()
stage: addChild(GameLost)
alert()
end
It gives an error that says 'attempt to call global youLoose (a nil value), where am I doing it wrong?
Note that collideswith is not the same as collidesWith; if that error you posted is correct, then you posted code that is different from what you are using. It could be that the method really is called collidesWith (it appears to be if it is the one from sprite1), but you used collideswith. Alternatively, if the code posted is what you used, then the error is likely attempt to call collideswith(a nil value), so cute.anim[1] is not a sprite1 object, but it is not nil either otherwise the error would be different.
Once you have fixed this, you'll notice that youLoose is defined after that for loop, when you call youLoose() it is not yet defined. You're going to have to move the local function youLoose() function to before the loop. Because the loop is not itself in a function, but is at module level, it gets executed before any following code, so any functions (local or global) that are used in the loop must be defined before the loop.
Note that "loose" does not mean the same as "lose". Check Grammar-monster to see difference. Probably everywhere you have the word "loose" you should change to "lose".

Resources