Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

why is Flora defined, but still nil?

Flora is defined, but when I try to call it I get nil. Any ideas?

Client

wait()
ReplicatedStorage = game:GetService("ReplicatedStorage")
floraEvent = ReplicatedStorage:WaitForChild("floraEvent")
flora =  ReplicatedStorage:WaitForChild("Flora")


function generateFlora(targ,node)
	local plant = flora:FindFirstChild(targ)  
		local p2 = plant:Clone() 
	p2.Parent = game.Workspace 
	p2.PrimaryPart.CFrame = node.CFrame
 
end 

floraEvent.OnClientEvent:Connect(function(...)
    local args = {...}
    for _, arg in pairs(args) do
        print(args[1].Name.."Located") 
    end

wait(.1) print (args[4]) print (args[5]) local v = args[4]
  generateFlora(v,args[5]) 

end)

Server


1 answer

✓ Accepted answer

Your code is going like this, it seems that your generate function cant check the variables targ, and node.

So now it will say: local plant = flora:FindFirstChild("medBushA") (instead of) local plant = flora:FindFirstChild(targ) targ isn't a thing but you still trying to find it in your flora folder, and for the p2.PrimaryPart.CFrame = node.CFrame, it's littery the same thing cause node is a variable and a variable doesn't have a CFrame, but yeah here is the correct code you can test it and leave me a like if it worked ;)

wait(2)
ReplicatedStorage = game:GetService("ReplicatedStorage")
floraEvent = ReplicatedStorage:WaitForChild("floraEvent")
flora =  ReplicatedStorage:WaitForChild("Flora")


function generateFlora(targ,node)
	local plant = flora:FindFirstChild("medBushA")  
		local p2 = plant:Clone() 
	p2.Parent = game.Workspace 
	print("Planted!")
--	p2.PrimaryPart.CFrame = node.CFrame
 
end 

floraEvent.OnClientEvent:Connect(function(...)
    local args = {...}
    for _, arg in pairs(args) do
        print(args[1].Name.."Located") 
    end

wait(.1) print (args[4]) print (args[5]) 
local v = args[4]
generateFlora(v, args[5]) 
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.